Chinaunix首页 | 论坛 | 博客
  • 博客访问: 207081
  • 博文数量: 80
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 824
  • 用 户 组: 普通用户
  • 注册时间: 2014-06-12 21:40
个人简介

只有今天的埋头,才有明天的出头。

文章分类

全部博文(80)

文章存档

2014年(80)

我的朋友

分类: LINUX

2014-12-21 21:01:29

#include
#include
#include
int main(void)
{
printf("The PID of the process is:%d\n",getpid());
printf("The PPID of the process is:%d\n",getppid());
return 0;
}
+++++++++++++++++++++++++++++++++
#include
#include
#include
#include
#include




int main()
{
pid_t c_pid,get_pid;
c_pid = fork();
if(c_pid < 0)
perror("fork");
else if(c_pid == 0)
{
printf("sleep 3s in child\n");
sleep(3);
exit(0);
}
else
{
do
{
get_pid = waitpid(c_pid,NULL,WNOHANG);
if(get_pid == 0)
{
printf("Child process has not exited\n");
sleep(1);
}

}while(!get_pid);
if(get_pid == c_pid)
printf("Child process has exited\n");
}
}
+++++++++++++++++++++++++++++

#include
#include
#include
int main()
{
char *arg[]={"env",NULL};
char *envp[]={"PATH=/tmp","USER=Webee",NULL};
if(fork()==0)
{
if(execve("/bin/env",arg,envp)<0)
perror("execve:");
}
}
+++++++++++++++++++++++++++++++++++++++++
#include
#include
#include


int main()
{
pid_t pid;
char *arg[]={NULL};
pid = fork();
if(pid == -1)
perror("fork:");
else if(pid ==0)
{
if(execv("/home/A8_test/print_something",arg)<0)
perror("execv:");
}
}
+++++++++++++++++++++++++++++++++++++
#include
#include
#include
#include
#include
int main()
{
if(fork()==0)
{
if(execlp("ps","ps","-ef",NULL)<0)
{
perror("execlp:");
exit(1);
}
}
return 0;
}
+++++++++++++++++++++++++++++++++++
#include
#include
#include




int main()
{
if(fork()==0)
{
if(execl("/bin/ls","ls","-l",NULL)<0)
perror("execl:");
}
return 0;
}



阅读(2578) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~