创建一个进程打开另外一个进程

#include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> int main (int argc,char **argv) { pid_t pid; if ((pid = fork()) < 0) { printf("fork error!/n"); exit(1); } else if (0 == pid) { printf("child process PID : %d./n",getpid()); setenv ("PS1","CHILD//$",1); printf("process %4d: calling exec./n",getpid()); if (execl("/home/deny/client.sh","argv[0]",NULL) < 0) { printf("process %4d: calling exec error!./n",getpid()); exit(0); } printf("process %4d : You should never see this,because the child is already gone./n",getpid()); printf("Process %4d : the chile process is exiting./n",getpid()); } else { printf("the parent process PID : %4d./n",getpid()); printf("chile process PID: %4d./n",pid); printf("process PID %4d: the child has called exec or has exited./n",getpid()); } return 0; } 

你可能感兴趣的:(创建一个进程打开另外一个进程)