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
  • 等等
相关推荐
热爱Liunx的丘丘人7 分钟前
Ansible的Playbook案例一
linux·运维·服务器·ansible
Minla14 分钟前
kubectl常用命令别名设置(linux|windows)
linux·运维·服务器·k8s
程序猿编码16 分钟前
给Linux程序穿“隐身衣”——ELF运行时加密器全解析(C/C++代码实现)
linux·c语言·c++·网络安全·elf·内存安全
cyber_两只龙宝23 分钟前
【Oracle】Oracle之SQL的聚合函数和分组
linux·运维·数据库·sql·云原生·oracle
做运维的阿瑞23 分钟前
Linux 系统启动过程解析
linux·运维·服务器
菜菜小狗的学习笔记23 分钟前
八股(六)操作系统
linux·运维·服务器
Goway_Hui29 分钟前
【ReactNative鸿蒙化-三方库使用与C-API集成】
c语言·react native·harmonyos
zhou7577121732 分钟前
linux搭建 Hermes Agent(爱马仕)
linux·运维·服务器
原来是猿38 分钟前
Linux线程同步与互斥(三):POSIX信号量与环形队列生产者消费者模型
linux·运维·服务器·开发语言
ic爱吃蓝莓1 小时前
破译 Linux 的“黑话”(常用命令解释)
linux·运维·服务器