Linux 内核的 current

1. 进程结构体

task_struct 是描述 Linux 进程的一个结构体,记录着进程的信息

cpp 复制代码
// include/linux/sched.h
struct task_struct {
	volatile long state;	/* -1 unrunnable, 0 runnable, >0 stopped */
	void *stack;
	atomic_t usage;
	unsigned int flags;	/* per process flags, defined below */
	unsigned int ptrace;
	.....
	.....
#ifdef CONFIG_UPROBES
	struct uprobe_task *utask;
#endif
#if defined(CONFIG_BCACHE) || defined(CONFIG_BCACHE_MODULE)
	unsigned int	sequential_io;
	unsigned int	sequential_io_avg;
#endif
#ifdef CONFIG_DEBUG_ATOMIC_SLEEP
	unsigned long	task_state_change;
#endif
};

2. current

current 宏其实就是静态函数 get_current()。它的返回值是一个 struct task_struct

c 复制代码
static inline struct task_struct *get_current(void)
{
	return current_thread_info()->task;
}

#define current get_current()

通过调用 current,我们可以获取当前的进程的信息:

  • current->comm: 进程的名字
  • current->pid: 进程的 pid
  • 等等
相关推荐
17(无规则自律)8 分钟前
【CSAPP 读书笔记】第二章:信息的表示和处理
linux·嵌入式硬件·考研·高考
!chen8 分钟前
linux服务器静默安装Oracle26ai
linux·运维·服务器
REDcker26 分钟前
Linux 文件描述符与 Socket 选项操作详解
linux·运维·网络
飞机和胖和黄27 分钟前
考研之王道C语言第三周
c语言·数据结构·考研
蒹葭玉树39 分钟前
【C++上岸】C++常见面试题目--操作系统篇(第二十八期)
linux·c++·面试
醉颜凉40 分钟前
【LeetCode】打家劫舍III
c语言·算法·leetcode·树 深度优先搜索·动态规划 二叉树
一匹电信狗42 分钟前
【LeetCode_21】合并两个有序链表
c语言·开发语言·数据结构·c++·算法·leetcode·stl
2501_927773071 小时前
imx6驱动
linux·运维·服务器
hy____1231 小时前
Linux_进程间通信
linux·运维·服务器
郭涤生1 小时前
C++的函数是否可以做到完全覆盖Linux和windows的跨平台
linux·c++·windows