Dave's Brain

Browse - Programming Tips - Why do I get a different number each time I list /proc/self ?

Date: 2012mar10
OS: Linux

Q.  Why do I get a different number each time I list /proc/self ?

A.  When you do:

cd /proc ls -l self
Example output:
lrwxrwxrwx 1 root root 64 Mar 9 23:32 self -> 17520/
A new process is started to run ls. Its the process id for ls you are seeing. From the shell you can do:
echo $$
to see your process id. Or:
PID=$$ echo My PID is $PID
in a shell script. From a C program do:
pit_t pid = getpid();
Still /proc/self is cool and useful. From a program you can read things from its folder.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.