Welcome, guest | Sign In | My Account | Store | Cart

判断一个进程还存不存在

C, 19 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
/**
 *@brief 判断一个进程还存不存在
 *
 */
int process_exist(pid_t pid){
    char buf[32] = {0};
    struct stat file_info;

    sprintf(buf, "/proc/%d",pid);

    errno = 0;
    if(-1 == stat(buf, &file_info) ){
        printf("\t\t\t %s : %s", buf, strerror(errno));
        return 0;
    }
    else{
        return 1;
    }
}
Created by J Y on Wed, 3 Jun 2009 (MIT)
C recipes (32)
J Y's recipes (21)

Required Modules

  • (none specified)

Other Information and Tasks