linux C语言编程 唤醒指定PID的进程

来源:百度知道 编辑:UC知道 时间:2024/06/08 04:44:08
我用fork()创建一进程,然后用pause()睡眠,如何唤醒这个进程?从fork()返回值已得到此进程PID,在线急等,谢谢

给你一个完整的测试代码:
--------------------------
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>

void handler(int signo)
{
printf("recv the signal from parent process\n");
}

int main()
{
pid_t pid;

pid = fork();

switch(pid)
{
case -1:
perror("fork failed");
exit(1);
case 0:
printf("in the child\n");
signal(SIGCONT, handler);
pause();
printf("child weakup\n");
break;
default:
printf("in the parent\n");
sleep(5);
kill(pid, SIGCONT);
sleep(5);
printf("parent weakup\n");
break;
}
printf("bye..\n");

exit(0);
}
-----------------------------------------------