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实现临时RAM登录的方法汇总
linux·前端·javascript
muxue17819 分钟前
chmod 777含义:
linux
帷幄庸者34 分钟前
CentOS 上配置 Docker 使用 NVIDIA GPU
linux·docker·centos
xbd_zc1 小时前
【Linux Nano Vim快捷键大全】
linux·运维·vim
shane-u1 小时前
Dockerfile实战:从零构建自定义CentOS镜像
linux·运维·centos
XiaoCCCcCCccCcccC1 小时前
Linux 的 UDP 网络编程 -- 回显服务器,翻译服务器
linux·网络·udp
风暴智能1 小时前
获取相机图像(ROS2)
linux·机器人·无人机
中国lanwp2 小时前
使用Maven和Ant上传文件到Linux服务器
linux·服务器·maven
孙克旭_2 小时前
day016-系统负载压力测试-磁盘管理
linux·运维·压力测试
liuyunluoxiao2 小时前
进程间通信--共享内存【Linux操作系统】
linux