i used to think that /proc/self
and /proc/$$
are the same in bash terminal, but now i find they are different.
i know $$
means the current process' pid, and /proc/self
is the currently running process, it should be bash terminal. why they are different?
root@VM-73-203-debian:~# echo $$
24415
root@VM-73-203-debian:~# ls -l /proc/self
lrwxrwxrwx 1 root root 0 Nov 22 2018 /proc/self -> 24465
root@VM-73-203-debian:~# ls -l /proc/$$
total 0
dr-xr-xr-x 2 root root 0 May 29 16:23 attr
...
$$
is a special bash variable that gets expanded to the pid of the shell.
/proc/self
is a real symbolic link to the /proc/
subdirectory of the process that is making the call.
When you do ls /proc/$$
the shell expands it to ls /proc/pid-of-bash
and that is what you see, the contents of the shell process.
But when you do ls /proc/self
you see the contents of the short lived ls
process.
The $$
is not limited to this usage, you can write echo $$
to see the bash pid; you can use it to kill yourself, etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With