Sachin Chourasiya Sachin Chourasiya - 1 year ago 122
C Question

Check running processes in C

Can some one please tell me how to check if a unix process with a given process id is running inside a C program. I know I can call system() and use the ps command but I dont want to call the system().

Answer Source

Using kill(2):

if (kill(pid, 0) == 0) {
    /* process is running or a zombie */
} else if (errno == ESRCH) {
    /* no such process with the given pid is running */
} else {
    /* some other error... use perror("...") or strerror(errno) to report */
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download