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
  • 等等
相关推荐
sunxunyong3 小时前
CGroup配置
linux·运维·服务器
hy____1234 小时前
Linux_网络编程套接字
linux·运维·网络
串口哑火达人4 小时前
(六)RT-Thread网络通信--AT组件与ESP8266
c语言·单片机·嵌入式硬件·mcu·物联网
若风的雨4 小时前
【deepseek】 Linux 调度延时分析
linux
2301_803554525 小时前
linux 以及 c++编程里对于进程,线程的操作
linux·运维·c++
LuDvei5 小时前
windows 中 vs code远程连接linux
linux·运维·服务器·windows
GDAL5 小时前
MANIFEST.in简介
linux·服务器·前端·python
点点滴滴的记录5 小时前
Redis部署在Linux上性能高于Windows
linux·数据库·redis
蜕变的小白5 小时前
基于Linux的天气查询项目
linux·运维·服务器
卤炖阑尾炎6 小时前
Linux firewalld 防火墙从入门到精通:原理与配置全解析
linux·运维·php