how to print the current process state
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);
}
}
Is there any other method or way to view the current process state in output
itself..?
Determining the scheduling state of a process is OS specific. On Linux,
topand similar read it from the third field in/proc/$PID/stat.