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
  • 等等
相关推荐
toooooop817 小时前
linux常用命令nano和vim有啥区别
linux·运维·vim
不只会拍照的程序猿17 小时前
《嵌入式AI筑基笔记03:Python流程控制,从C的严谨到Python的简洁》
c语言·开发语言·笔记·python
i建模17 小时前
在Ubuntu中解压ZIP文件
linux·chrome·ubuntu
handler0117 小时前
算法:字符串哈希
c语言·数据结构·c++·笔记·算法·哈希算法·散列表
雨落在了我的手上17 小时前
C语言之数据结构初见篇(5):单链表的介绍(1)
c语言·开发语言·数据结构
鹏大师运维17 小时前
统信UOS上使用WPS PDF独立版
linux·运维·windows·pdf·wps·统信uos·wine
szm022517 小时前
操作系统-
java·linux·服务器
暴力求解17 小时前
Linux---进程间通信
linux·运维·服务器
桑榆肖物18 小时前
.NET 10 Native AOT 在 Linux 嵌入式设备上的实战
java·linux·.net·aot
YMWM_18 小时前
磁盘的分区格式MBR和GPT的区别
linux·磁盘分区