Reputation: 1157
I have to retrieve process status(whether process is running or stopped) whose procees id is given from my c program(i am using linux). i planned to use exec command and written below statement
execv("ps -el|grep |awk '{print $2}'",NULL);
But it is not giving me desired output.
Please let me know where i am wrong.
Upvotes: 0
Views: 829
Reputation: 61
I doubt exec is the family of calls you require here. system(3) might be more ideal.
Upvotes: 1
Reputation: 111
The exec call returns the error code corresponding to whether the execution of the program was successful or not.
If you fork a child process and then exec the command in the child process, you can read the its exit status in the parent process using the waitpid call.
Upvotes: 1
Reputation: 239331
The third field in /proc/<pid>/stat
contains the process status: R
if it's Running, S
if it's Sleeping (there's a few others too, like D
for Disk Wait and Z
for Zombie).
Upvotes: 3