https://www.centos.org/docs/5/html/5.2/Deployment_Guide/s3-proc-self.html
says
The
/proc/self/
directory is a link to the currently running process.
There are always multiple processes running concurrently, so which process is "the currently running process"?
Does "the currently running process" have anything to do with which process is currently running on the CPU, considering context switching?
Does "the currently running process" have nothing to do with foreground and background processes?
Best Answer
This has nothing to do with foreground and background processes; it only has to do with the currently running process. When the kernel has to answer the question “What does
/proc/self
point to?”, it simply picks the currently-scheduled pid, i.e. the currently running process (on the current logical CPU). The effect is that/proc/self
always points to the asking program's pid; if you runyou'll see
ls
's pid, if you write code which uses/proc/self
that code will see its own pid, etc.