>>Hi, I am trying to get the status of a process, whether it's still running
>>or terminated, given its pid using waitpid(). My code looks something
>>pid_t pid = retrieveMyPid(); //gets the pid from a list
>>waitpid (pid, &status, WNOHANG);
>> printf("Process Done\n");
>> printf("Process Running\n");
>>But somehow status doesn't get any value and remains as zero no matter if
>>I have the process still running or not. Any suggestions?
> waitpid is for use with the child processes, ie the one you created
> with fork().
> Maybe it's not the case here ?
> If your system has a /proc filesystem, you can try to access /proc/<pid>.
> If there is no such directory, surely the process doesn't run anymore.
> If there is, it might be the process you want, or it can be another one,
> since pids are reallocated later (typically pids range from 0
> to 32767, I am not really sure of the upper bound though...).
> So, it's a bit tricky to know if the process you watch is still
> there or not. If it's a child, waitpid is enough, though.
Yes, the process is a child process created by fork(). By calling waitpid()
with a process (something like 5746 from running DDD), it should return the
status of that process. But strangely the value of status never changes
from what's given at initial declaration. Did I do something wrong? Is
there someother function I can call to retrieve the status of a process?