进程的 pid、ppid、uid、euid、gid 和 egid 之间有什么区别?

What is the difference between a Process' pid, ppid, uid, euid, gid and egid?

上下文:我正在获取当前 Ruby 进程 ID。

Process.pid  #=> 95291

Process.ppid #=> 95201

Process.uid  #=> 501

Process.gid  #=> 20

Process.euid #=> 501

Process.egid #=> 20

顺序:

  • pid: 是你调用Process.pid方法的进程的进程号(PID)。
  • ppid:父进程(产生当前进程的进程)的 PI​​D。例如,如果您在 bash shell 中 运行 ruby test.rb,则该进程中的 PPID 将是 Bash 的 PID。
  • uid:进程所在的用户的 UNIX ID 运行ning。
  • euid:进程 运行ning 所属的 有效 用户 ID。 EUID 根据允许使用此 UID 的用户执行的操作来确定允许程序执行的操作。通常与 uid 相同,但可能与 sudo 等命令不同。
  • gid:程序 运行ning 所在的 UNIX 组 ID。
  • egid:类似于 euid,但适用于群组。

PID:

In Linux, an executable stored on disk is called a program, and a program loaded into memory and running is called a process. When a process is started, it is given a unique number called process ID (PID) that identifies that process to the system. If you ever need to kill a process, for example, you can refer to it by its PID.

PPID:

In addition to a unique process ID, each process is assigned a parent process ID (PPID) that tells which process started it. The PPID is the PID of the process’s parent.

For example, if process1 with a PID of 101 starts a process named process2, then process2 will be given a unique PID, such as 3240, but it will be given the PPID of 101. It’s a parent-child relationship. A single parent process may spawn several child processes, each with a unique PID but all sharing the same PPID.

UID:

Unix-like operating systems identify users within the kernel by a value called a user identifier, often abbreviated to UID or User ID. The UID, along with the GID and other access control criteria, is used to determine which system resources a user can access. The password file maps textual usernames to UIDs, but in the kernel, only UID's are used.

EUID:

The effective UID (euid) of a process is used for most access checks. It is also used as the owner for files created by that process.

GID:

A group identifier, often abbreviated to GID, is a numeric value used to represent a specific group. The range of values for a GID varies amongst different systems; at the very least, a GID can be between 0 and 32,767, with one restriction: the login group for the superuser must have GID 0.

EGID:

The effective GID (egid) of a process also affects access control and may also affect file creation, depending on the semantics of the specific kernel implementation in use and possibly the mount options used.

有关详细信息,请参阅这些文章:

  1. What are PID and PPID?
  2. Meaning of PID, PPID and TGID
  3. User identifier
  4. Group identifier

除了上述综合答案外,我还想分享一些 linux 命令和相应的输出,这可能有助于实现 real 和 [=19] 之间的区别=]effective user id/group for current logged in user myuser:

真实用户名和组名以及数字 ID

$ id

uid=1000(myuser) gid=1000(myuser) groups=1000(myuser),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),119(lpadmin),130(lxd),131(sambashare)

有效的用户名和组名以及数字 ID

$ sudo id

uid=0(root) gid=0(root) groups=0(root)