1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > linux c 获取指定进程 父进程pid

linux c 获取指定进程 父进程pid

时间:2020-10-17 08:46:40

相关推荐

linux c 获取指定进程 父进程pid

示例如下:

int GetFatherPid(int pid){char dir[1024]={0};char path[1024] = {0};char buf[1024] = {0};int rpid = 0;int fpid=0;char fpth[1024]={0};struct stat st;ssize_t ret =0;sprintf(dir,"/proc/%d/",pid);sprintf(path,"%sstat",dir);if(stat(path,&st)!=0){return -2; }memset(buf,0,strlen(buf));FILE * fp = fopen(path,"r");ret += fread(buf + ret,1,300-ret,fp);fclose(fp);sscanf(buf,"%*d %*c%s %*c %d %*s",fpth,&fpid);fpth[strlen(fpth)-1]='\0';return rpid;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。