2016年7月26日 星期二

[C] Check pid alive

#include<stdio.h>
#include <sys/types.h>
#include <sys/stat.h>

static int Check_pid_alive( pid_t pid )
{
    struct stat buf;
    char path[32];

    /* Check the existance of the pid command line file */
    sprintf( path, "/proc/%d", pid );

    if( stat(path, &buf) )
        return 0;

    return 1;
}

int main(int argc, char **argv)
{
    printf("%d\n",Check_pid_alive(atoi(argv[1])));
}

0 意見:

張貼留言