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
  • 等等
相关推荐
筱白爱学习1 小时前
RestHighLevelClient详细使用手册
linux·服务器·php
若谷老师1 小时前
21.WSL中部署gnina分子对接程序ds
linux·人工智能·ubuntu·卷积神经网络·gnina·smina
敲皮裤的代码2 小时前
《C语言》深入理解指针(4)
c语言
J-TS3 小时前
线性自抗扰控制LADRC
c语言·人工智能·stm32·单片机·算法
啊辉的科研3 小时前
植物单细胞RNA-seq分析教程3-2025年版
linux·r语言
A9better3 小时前
C++——指针与内存
c语言·开发语言·c++·学习
坚持编程的菜鸟3 小时前
互质数的个数
c语言·算法
Norach4 小时前
ubuntu22.04安装ssh-server与realvnc-server
linux·服务器·经验分享·ubuntu·ssh·vnc
UP_Continue4 小时前
Linux--进程间通信
linux·运维·服务器
kaoa0004 小时前
Linux入门攻坚——67、MySQL数据库-4
linux·运维·数据库·mysql