View Process State
We can view Linux process by ps or top, major difference between them is that,
ps shows a static state at that time point, while
top dynamically shows process status
There's a field called "S" or "STAT" in ps & top echo.
These two fields indicate the process states.
Examples:
Process State Definition
In Linux, processes have below states:
D uninterruptiabe sleep (usually IO) (struct: task_uninterruptible)
R running or runnable (on run queue) (struct: task_running)
S interuptable sleep (waiting for an event to complete) (struct: task_interruptible)
T stopped, either by a job control signal or because it is being traced (struct: task_stopped or task_traced)
W paging (not valid since the 2.6.xx kernel) (struct: )
X dead (should never be seen) (struct: task_dead)
Z defunct ("zombie") proces, terminated but not reaped by its parent
Parent Process and Child Process
In Linux programming, fork() will make a child process which is almost the same with the parent process.
For example:
#include <stdio.h> #include <unistd.h> //including fork(), getpid(), getppid(), etc. main() { if (!fork()) { printf("Child pid=%d\n",getpid()); exit(0); } printf("parent pid=%d\n",getpid()); exit(0); }