一个进程可以有一个所有者吗?这是什么意思?

Nag*_*ini 9 linux process users

我们可以通过使用该ps命令来确定进程的所有者。这是否意味着其他用户无法运行/杀死/恢复该进程?

Bas*_*tch 18

读取凭据(7)fork(2)execve(2)。该系统调用fork是过程的创建方法(在今天,fork经常与实施克隆(2) ,但你可以看到,作为一个实现细节)。该exec系统调用是这样的可执行程序被启动。请记住,一切都是从某个进程通过一些系统调用(在syscalls(2) 中列出)完成的。内核在启动时神奇地启动了第一个进程(initsystemd)。其他进程已启动fork(2). 现代的Linux内核有时-但很少-神奇地启动一些特殊工艺(如/sbin/hotplug)或内核线程(例如kworkerkswapd....)。

所以是的,每个进程(和每个文件)都有一些所有者(技术上是uid,一个小的非负数)和组(gid)。0 uid 用于 root 并具有额外的权限。

另请阅读有关setuid(和setreuid(2) ...)的信息,这很棘手。

这是否意味着其他所有者无法运行该进程?

一个进程已经在运行(但它可能处于空闲或等待状态),所以没有人可以再次运行它。不要将进程(动态的东西)与在其中运行的程序(一个可执行文件,通常采用ELF格式)混淆。

一个给定的程序(例如/bin/bash)可以在多个进程中执行。许多可执行文件保留在您的磁盘上,而没有(在给定时刻)任何进程运行它们。

在 Linux 上,proc(5)对于查询内核进程状态非常有用。尝试示例cat /proc/$$/statuscat /proc/self/maps. 另请参阅pgrep(1)ps(1)top(1)

每个进程都有自己的虚拟地址空间,自己的文件描述符表,自己的工作目录,(通常还有几个线程,参见pthreads(7))等等……

这是否意味着其他所有者无法运行/终止/恢复该进程?

运行一个进程没有任何意义(它已经在运行)。但是,pid 1234 进程的可执行文件可用作/proc/1234/exe符号链接,您可以将其用于execve(2) - 但您可能不应该-。的权限规则execve适用。

杀死(2)一个进程,您通常应该具有相同的 uid。但是,文档说明:

  For a process to have permission to send a signal, it must either be
   privileged (under Linux: have the CAP_KILL capability in the user
   namespace of the target process), or the real or effective user ID of
   the sending process must equal the real or saved set-user-ID of the
   target process.  In the case of SIGCONT, it suffices when the sending
   and receiving processes belong to the same session. 
Run Code Online (Sandbox Code Playgroud)

停止进程,请使用与kill(2)一起使用的SIGSTOP(或SIGTSTP) 信号。见信号(7)

恢复停止的进程,请使用该SIGCONT信号。