The system assigns to every process an integer number that is called the process id (or pid). With this it can easily identify any process running. Knowing the number of a process, we can ask the kernel to give us any other information about the process, and also send signals to the process, as we will see later on.
Starting a process inside UNIX is only possible by using another process. This way, every process belongs to another process and every child process will have a parent process. When the system starts up and the kernel starts to build the OS, it will first start a process entitled “init.” This will start the process that will take care of the time slice operation and distribution/schedule of processes for the CPU times.
We refer to this process most of the time as the number 0 process. Its name differs from OS to OS; however, it is one off from the sched, swapper, and kernel. The ps command will not list this. This way, the first real process is the init to which the number 1 process identifier is assigned. All other processes will be started by the init or a child of this. Draw this on a sketch and you will have a tree like structure. With the pstree command inside a terminal you can view exactly this:
Following this rule, a shell script we start from a terminal will also be the child of the terminal, and the script itself will be a process on its own. Inside a shell script, the process identifier of the script is stored in the $$ special variable.
#!/bin/bash
echo $$
This will print the process identifier of the script. Observe that this is a different number each time you start the script. This is due the fact that numbers are assigned one after another for every process, and this is always unique. There aren’t two with the same pid in the same time.