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
  • 等等
相关推荐
qq_339191147 分钟前
uv 设置系统默认版本, linux设置uv
linux·运维·uv
似水এ᭄往昔16 分钟前
【Linux】--进程概念
linux·运维·服务器
IDIOT___IDIOT17 分钟前
Linux 使用 `cp` 命令导致挂载点被覆盖问题记录
linux·运维·服务器
老约家的可汗27 分钟前
list 容器详解:基本介绍与常见使用
c语言·数据结构·c++·list
顶点多余34 分钟前
线程互斥+线程同步+生产消费模型
java·linux·开发语言·c++
李彦亮老师(本人)37 分钟前
Rocky Linux 9.x 安全加固实战指南:从系统初始化到生产级防护
linux·运维·安全·rocky
RisunJan1 小时前
Linux命令-mount(用于挂载Linux系统外的文件)
linux·运维·服务器
脆皮炸鸡7551 小时前
Linux开发工具~~~版本控制器Git以及调试工具GDB
linux·服务器·开发语言·经验分享·git·学习方法
xuejiazhi2 小时前
在Ubuntu下安装OpenClaw
linux·运维·服务器
爱编码的小八嘎2 小时前
C语言完美演绎6-10
c语言