Kill用法举例

/*
 * 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);
}


原文地址:https://www.cnblogs.com/MockingBirdHome/p/3040874.html