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
  • 等等
相关推荐
123过去6 小时前
wifi-honey使用教程
linux·网络·测试工具
Deitymoon8 小时前
linux——孤儿进程和僵尸进程
linux
Linux运维技术栈10 小时前
生产环境Linux应用目录迁移至LVM独立分区 标准化实战方案
linux·运维·服务器·lvm·逻辑卷
feasibility.10 小时前
SSH Agent Forwarding 与 tmux 排障笔记
linux·运维·服务器·经验分享·笔记·ssh
ShawnLiaoking10 小时前
Linux 会话窗口常开
linux·运维·服务器
230万光年的思念10 小时前
向日葵远程控制ubuntu24一直显示连接中
linux
IMPYLH12 小时前
Linux 的 dir 命令
linux·运维·服务器·数据库
fanged12 小时前
操作系统番外1(Linux的测试体系)(TODO)
linux·运维·服务器
平凡灵感码头13 小时前
C语言 printf 数据打印格式速查表
c语言·开发语言·算法
123过去13 小时前
pixiewps使用教程
linux·网络·测试工具·算法·哈希算法