如何打印当前进程状态
main ()
{
pid_t pid;
printf("parent : %d\n", getpid());
pid = fork();
if (pid == 0)
{
printf("child : %d\n", getpid());
sleep(2);
printf("child exit\n");
exit(1);
}
while (1)
{ /*after the child exit, its a zombie process */
system("clear");
system("ps -x | grep t"); /* if a.out is Z means zombie process */
sleep(8);
}
}
是否有任何其他方法或方式可以在输出中查看当前进程状态 本身..?
最佳答案
确定进程的调度状态是特定于操作系统的。在 Linux 上,top
和类似的从 /proc/$PID/stat
中的第三个字段读取它。
关于c - 如何在程序输出本身中查看当前进程状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14641254/