“Process management” as name itself means to manage the processes. And in terms of Linux OS, processes means “executing instance” of a program or we can use a word “tasks” for processes.
Example: when ever we copy a file or folder from one location to another in windows OS it usually displays a graph , a moving file, time remaining, how much memory remaining etc. All such things are called processes. But you must have noticed one thing that actually these are different processes which runs under a same program.
so there is parent process and child process. The process which creates another process is called parent process and latter is called child process. And each process has its own PID i.e. process identity number to distinguish the child from the parent.
To get these process IDs in the program
The functions are
getpid() // to get the current process id
getppid() // to get the creator/ parent process id
There are three methods of creating a process:
1. Create a process with the use of loader from file system.
2. Create a process from the code segment of the current program using system call
3. Duplication of the program
The easiest one is to use a Duplication of a program
To create a process using this method is done by using “fork()”
fork function is a special function use to create a child process from a parent process. Using fork(), child process shares the code segment of its parent but both processes have different physical address. After completion of the child process, child process returns its control to parent and the parent process returns its control to the shell.
child PID= parent PID + 1
PPID of child = PID of parent
fork() returns three values and we can use these values to know which process is executing
fork() returns following values
0 (zero) : if the process is executed by child
+ve value : means child is created and +ve value is child’s PID
-ve value : ERROR…! i.e. child process is not created.
NOTE: child process and Parent process both are the part of same program and execute at the same time. It depends on the scheduler that which process executes in which order…….!
Rest i will surely update about how to manage these processes and i will add more stuff related to Process management ….soon…!