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
  • 等等
相关推荐
lThE ANDE8 小时前
最完整版Linux安装Redis(保姆教程)
linux·运维·redis
郝亚军12 小时前
ubuntu通过samba,让win11可以访问其共享文件夹
linux·服务器·ubuntu
一个人旅程~12 小时前
旧电脑的“拯救者”?Linux Mint20.3是怎样适配软件硬件以及兼顾兼容与性能的平衡的?
linux·经验分享·电脑
小夏子_riotous12 小时前
Docker学习路径——3、常用命令
linux·运维·服务器·学习·docker·容器·centos
其实防守也摸鱼13 小时前
无线网络安全---WLAN相关安全工具--kali(理论附题目)
linux·安全·web安全·学习笔记·kali·命令模式·wlan
glimix13 小时前
Word-Pop:使用C语言开发打单词游戏
c语言·游戏
uesowys14 小时前
CentOS Linux安装部署OpenClaw
linux·centos·安装部署openclaw
IMPYLH14 小时前
Linux 的 rm 命令
linux·运维·服务器·网络·bash
YIN_尹15 小时前
【Linux系统编程】进程地址空间
linux·c++
代码中介商16 小时前
手把手教你Linux 打包压缩与 gcc 编译详解
linux·运维·服务器·编译·打包·压缩