UNIX环境高级编程学习之第八章进程控制-用父子进程实现打开kate,返回kate关闭状态 #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <errno.h> int main() { pid_t pid= fork(); if (pid < 0) { printf("fork error msg=%s/n", strerror(errno)); exit(-1); }else if (pid == 0) // clild process { execlp("kate", "kate > /dev/null", "./fork.c",(char*)0); }else{ // parent process int ret; waitpid(pid, &ret, 0); printf("pid = %u, ret = %d/n", pid, ret); } return 0; }