linux内核源码中的“current”是什么?

我正在学习关于Linux内核,我有一个问题

我看到很多linux内核源文件都有current-> files。 那么什么是“当前”?

struct file *fget(unsigned int fd) { struct file *file; struct files_struct *files = current->files; rcu_read_lock(); file = fcheck_files(files, fd); if (file) { /* File object ref couldn't be taken */ if (file->f_mode & FMODE_PATH || !atomic_long_inc_not_zero(&file->f_count)) file = NULL; } rcu_read_unlock(); return file; } 

这是一个指向当前进程的指针(即发出系统调用的进程)。

在x86上,它是在arch/x86/include/current.h (类似于其他arch/x86/include/current.h文件)。

 #ifndef _ASM_X86_CURRENT_H #define _ASM_X86_CURRENT_H #include <linux/compiler.h> #include <asm/percpu.h> #ifndef __ASSEMBLY__ struct task_struct; DECLARE_PER_CPU(struct task_struct *, current_task); static __always_inline struct task_struct *get_current(void) { return percpu_read_stable(current_task); } #define current get_current() #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_CURRENT_H */ 

Linux设备驱动程序第2章中的更多信息:

当前指针指的是当前正在执行的用户进程。 在执行系统调用期间,例如打开或读取,当前进程是调用该调用的进程。 如果需要的话,内核代码可以通过使用current来使用特定于进程的信息。 […]

Current是类型struct task_struct的全局变量。 你可以在[1]找到它的定义。

Files是一个struct files_struct ,它包含当前进程使用的文件的信息。

[1] http://students.mimuw.edu.pl/SO/LabLinux/PROCESY/ZRODLA/sched.h.html