/*
* Killing other processes
*/
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/types.h>
int main()
{
pid_t child;
int status, retval;
if((child = fork()) < 0)
{
perror ("fork");
exit (EXIT_FAILURE);
}
if(child == 0)
{
sleep (1000);
exit (EXIT_SUCCESS);
}
else
{
if((waitpid(child, &status, WNOHANG)) == 0)
{
retval = kill (child, SIGKILL);
if (retval)
{
puts ("kill failed\n");
perror ("kill");
waitpid (child, &status, 0);
}
else
printf ("%d killed\n", child);
}
}
exit (EXIT_SUCCESS);
}
Kill用法举例
最新推荐文章于 2021-06-14 14:50:06 发布