|
|
程序如下:
[php]
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int
main ()
{
int fds[2];
pid_t pid;
pipe (fds);
pid = fork ();
if(pid==0)
{
pid=fork();
if(pid==0)
{
printf("chld pid=%d\n",getpid());
execlp("mplayer","mplayer","http://localhost:9000",0);
}
else
{
close(fds[0]);
dup2(fds[1],1);
printf("%d ",pid);
}
}
else
{
close(fds[1]);
char aa[20];
read(fds[0],aa,15);
sleep(4);
kill(atoi(aa),SIGKILL);
}
}
[/php]
gcc编译成a.out,
首先运行
sp-sc sop://broker.sopcast.org:3919/official/shanghaiGsports 8000 9000
然后运行
./a.out
4秒后mplayer退出,用ps -aux查看进程,发现mplayer还在。按理说mplayer进程是由init管理的,它的僵尸进程应该由init自动处理的。 |
|