C Tutorial: Playing with processes
Getting a process' process ID (PID)
Every process on the system has a unique process ID number, known as the pid. This is simply an integer. You can get the pid for a process via the getpid system call.
Example
This is a small program that simply prints its process ID number and exits.
Save this file by control-clicking or right clicking the download link and then saving it as getpid.c.
Compile this program via:
If you don't have gcc, You may need to substitute the gcc command with cc or another name of your compiler.
Run the program: