Each time, when the command
ls -l /proc/self is executed, the link points to process who's PID keeps increasing. Why is this so ? Is it the PID of the
ls command ?
Yes, that's the PID of ls.
ls as an external command, so anytime you run
ls, the shell must create new process and run
ls in that process.
To do that, the shell will call execve() system call:
$ strace ls -l /proc/self execve("/bin/ls", ["ls", "-l", "/proc/self"], [/* 76 vars */]) = 0
You can see, after new process was created,
/proc/self belongs to context of that process, so it was expanded to the PID of
Yes, it's the PID of
/proc/self This directory refers to the process accessing the /proc file system, and is identical to the /proc directory named by the process ID of the same process.
man 5 proc)
/proc/self is a symbolic link to
/proc/PID for the PID of the process that accesses the link, by the magic of the
In your case, that process is
ls, and so each time you run the command you get a different PID (which tends to increase).