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:

Zombie process 僵尸进程

Zombie process 僵尸进程

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)

defunct ("zombie") proces, terminated but not reaped by its parent

Zombie process 僵尸进程

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);
}
fork a process

相关文章:

  • 2022-12-23
  • 2021-11-20
  • 2021-11-20
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2022-02-07
  • 2021-06-09
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
相关资源
相似解决方案