所有栏目

getppid

作者:爱百科

getppid(取得父进程的进程识别码)

getppid详细介绍

getppid(取得父进程的进程识别码)

getppid简介

相关函数 fork,kill,getpid

表头文件 #include<unistd.h>

定义函数 pid_t getppid(void);

函数说明 getppid()用来取得目前进程的父进程识别码。

返回值 目前进程的父进程识别码。

范例1

#include<unistd.h>

main()

{

printf(“My parent ‘pid =%dn”,getppid());

}

执行

My parent ‘pid =463

范例2

#include <sys/types.h>

#include <unistd.h>

int main(){

pid_t pid=fork();

if(pid==0){

printf("ni am childn");

printf("My process id is %dn",getpid());

printf("My Parents's process id is %dn",getppid());

}

else{

printf("i am parentn");

printf("My process id is %dn",getpid());

printf("My parents's process id is %dn",getppid());

sleep(1);}}

getppid执行结果

i am parent

My process id is 220

My parents's process id is 119

#i am child

My process id is 221

My Parents's process id is220

热点导航
教育资讯 知道问答 公考资讯 司法考试 建筑知识 工作范文 大学排名 报考专业 学习方法 句子美文 秒知回答 作业解答 精选答案 知途问学