【发布时间】:2016-05-31 02:52:58
【问题描述】:
我希望我的子进程在我的父母等待 3 秒并杀死孩子时执行 bin 程序。傻我知道,但还是得做。似乎无法在这里正确使用 execv。我尝试运行日历、gedit 等,但对我没有用。有什么建议 ?
int main(int argc, char* argv[])
{
pid_t pid;
pid = fork();
if (pid == 0) {
execv("calc",argv);
return 0;
}
else if (pid > 0) { /* parent process */
sleep(3);
kill(pid, SIGKILL);
printf("Child process with the ID: %d has been killed by the parent process with the ID: %d...\n", pid, getpid());
return 0;
}
}
【问题讨论】:
标签: c process operating-system exec child-process