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 小时前
外卖餐具智能推荐
linux·服务器·前端
Tomhex2 小时前
C语言内存安全防护指南
c语言
皮皮林5512 小时前
强烈建议大家使用 Linux 做开发?
linux
IMPYLH2 小时前
Linux 的 od 命令
linux·运维·服务器·bash
Kk.08023 小时前
Linux(十一)fork实例练习、文件操作示例及相关面试题目分享
linux·运维·算法
230万光年的思念4 小时前
zerotier连不上的问题
c语言
数据雕塑家4 小时前
Linux下大文件切割与合并实战:解决FAT32文件系统传输限制
linux·运维·服务器
IMPYLH4 小时前
Linux 的 nice 命令
linux·运维·服务器·bash
l1o3v1e4ding4 小时前
排查linux CentOS7.6的mysql磁盘 I/O 延迟过高问题
linux·运维·mysql
Edward111111116 小时前
linux创建普通用户
linux·运维·服务器