进程

#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
#include<sys/wait.h>
#include<sys/types.h>

int main()
{
 pid_t t;
 char buf[] = "test!";
 t = fork();//创建一个子进程
 if(t == 0){
  printf("child\n");
  printf("C: %s\n",buf);
  execlp("ls","ls","-l",NULL);//让子进程去执行另外的任务
  exit(0);
 }
 else{
  waitpid(t,NULL,0);//等待子进程退出
  printf("parent\n");
  printf("P: %s\n",buf);
 }
 return 0;
}

posted on 2012-04-07 19:31  小风儿_xf  阅读(135)  评论(0编辑  收藏  举报

导航