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
  • 等等
相关推荐
青禾83711 小时前
Linux 操作系统入门指南:从目录结构到常用命令
linux·运维·服务器
闖6412 小时前
入门Linux操作系统|零基础吃透原理、目录、权限、常用命令
linux
bruk_spp13 小时前
linux pinctrl
linux
en.en..14 小时前
Linux系统编程:fcntl 与 ioctl
linux·运维·服务器
自动化监测Learner15 小时前
Navicat Premium 17 中文版安装教程(2026最新版)
java·linux·数据库
pingglala16 小时前
ubuntu-nat模式不能上网解决方法
linux·运维·ubuntu
Zixhy17 小时前
多点巡检机器人项目技术总结
linux·c++·机器人·自动驾驶
雯宝17 小时前
7. USB 网络适配器驱动
linux
rest102417 小时前
使用内存探测bpf
linux
重生之我来学Python18 小时前
Docker套装的简介、安装、超级详细教程
linux·docker·容器·eureka·github