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
  • 等等
相关推荐
旖旎夜光9 小时前
Linux(9)
linux·学习
喵了meme10 小时前
Linux学习日记24:Linux网络编程基础
linux·网络·学习
whlqjn_121111 小时前
linux下使用SHC对Shell脚本进行封装和源码隐藏
linux·centos
weixin_4624462311 小时前
K8s 集群部署基础:Linux 三节点 SSH 互信(免密登录)配置指南
linux·kubernetes·ssh
Hard but lovely12 小时前
Linux: 线程同步-- 基于条件变量 &&生产消费模型
linux·开发语言·c++
m0_7381207212 小时前
应急响应——知攻善防靶场Linux-1详细应急过程
linux·运维·服务器·网络·web安全·ssh
Guistar~~12 小时前
【Linux驱动开发IMX6ULL】WS73 驱动移植的详细教程基于USB协议--WIFi网卡、蓝牙BLE、星闪SLE
linux·驱动开发
GHL28427109012 小时前
无法连接服务端socket
linux·服务器·网络
阿华hhh12 小时前
项目(购物商城)
linux·服务器·c语言·c++
方便面不加香菜13 小时前
基于顺序表实现通讯录项目
c语言·数据结构