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
  • 等等
相关推荐
m0_531237171 小时前
C语言-指针终阶
c语言·开发语言
散峰而望1 小时前
C++ 启程:从历史到实战,揭开命名空间的神秘面纱
c语言·开发语言·数据结构·c++·算法·github·visual studio
huaweichenai1 小时前
Linux安装http-server并部署html静态站点
linux·运维·服务器
Gss7772 小时前
Linux 正则表达式详解(基础 + 扩展 + 实操)
linux·运维·正则表达式
北冥湖畔的燕雀2 小时前
Linux权限与Vim,gcc以及make/makefile操作全解析
linux·运维·服务器
代码游侠2 小时前
Linux驱动复习——驱动
linux·运维·arm开发·笔记·学习
水饺编程2 小时前
第4章,[标签 Win32] :TextOut 测试案例3代码改编
c语言·c++·windows·visual studio
LuDvei2 小时前
LINUX文件操作函数
java·linux·算法
czxyvX3 小时前
017-Linux-网络基础概念
linux·网络
一个人旅程~3 小时前
win10LTSB2016与win10LTSC2019对于老机型哪个更合适?
linux·windows·经验分享·电脑