Friday, March 02, 2007

How to know the current process state

This one feature though trivial will be thoughly learnt on a need basis.

When we need to find out what is the current state of a process is (aka Running(R), Sleeping(S), Stopped(T),Zombie(Z) etc), we can use the ps command effectively.

Here is the basic setup
test@shantanu>more simple1.c
#include
int main()
{
int i=0;
printf("Waiting for a console output\n");
scanf("%d",&i);
return(0);
}
test@shantanu>gcc simple1.c -o simple1
test@shantanu>./simple1
Waiting for a console output
........///No input is yet given

In another terminal run
test@shantanu>ps -a -o comm -o s|grep simple1
./simple1 S

So the process is currently sleeping for my input.
All the state changes hereafter can be observed independently.

No comments: