本文章已收录于:
分类:
作者同类文章
X
版权声明:本文为博主原创文章,未经博主允许不得转载。
功能描述:
getpid返回当前进程标识,getppid返回父进程标识。
getpid返回当前进程标识,getppid返回父进程标识。
用法:
#include <sys/types.h>
#include <unistd.h>
pid_t getpid(void);
pid_t getppid(void);
例子:
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
int main(void)
{
pid_t pid;
printf("Before fork .../n");
switch(pid = fork()) {
case -1:
printf("Fock call fail/n");
exit(1);
case 0:
printf("The pid of child is: %d/n", getpid());
printf("The pid of child's parent is: %d/n", getppid());
printf("Child exiting.../n");
exit(0);
default:
printf("The pid of parent is: %d/n", getpid());
printf("the pid of parent's child is: %d/n", pid);
}
printf("After fork, program exiting.../n");
exit(0);
}
-
顶
- 0
-
踩
- 0
- 上一篇fork函数剖析
- 下一篇UNIX 进程揭秘--进程的生命周期
我的同类文章
http://blog.csdn.net
- •What is a Distributed System?2008-03-12
- •VMware安装及基于系统安装手册2008-03-07
- •Fedora Core && VMware2008-03-06
- •unix-关于信号、信号处理函数2008-03-03
- •套接口编程基础2008-03-01
- •UNIX 进程--多任务原理2008-02-16
- •X Window System2008-03-08
- •在windows XP下如何用Vmware装Linux操作系统2008-03-07
- •函数名做函数参数2008-03-04
- •Linux编程:信号篇 2008-03-03
- •僵尸进程(zombie process)2008-02-27