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
  • 等等
相关推荐
Coder个人博客4 小时前
Linux6.19-ARM64 mm mmu子模块深入分析
大数据·linux·车载系统·系统架构·系统安全·鸿蒙系统
Doro再努力7 小时前
Vim 快速上手实操手册:从入门到生产环境实战
linux·编辑器·vim
wypywyp7 小时前
8. ubuntu 虚拟机 linux 服务器 TCP/IP 概念辨析
linux·服务器·ubuntu
Doro再努力7 小时前
【Linux操作系统10】Makefile深度解析:从依赖推导到有效编译
android·linux·运维·服务器·编辑器·vim
senijusene7 小时前
Linux软件编程:IO编程,标准IO(1)
linux·运维·服务器
忧郁的橙子.7 小时前
02-本地部署Ollama、Python
linux·运维·服务器
醇氧7 小时前
【linux】查看发行版信息
linux·运维·服务器
No8g攻城狮8 小时前
【Linux】Windows11 安装 WSL2 并运行 Ubuntu 22.04 详细操作步骤
linux·运维·ubuntu
XiaoFan0128 小时前
免密批量抓取日志并集中输出
java·linux·服务器
souyuanzhanvip8 小时前
ServerBox v1.0.1316 跨平台 Linux 服务器管理工具
linux·运维·服务器