The key to sending a signal is to let the system know which process to send the signal and what signal to send. It should be noted that the ability to send a particular signal to a process is closely related to the user's permissions. For example, only a system administrator can send a sigkill signal to terminate a process.
A system call used to send a signal.
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
#include <sys/ time.h>
int Kill (pid_t pid,int signumber);
int raise (int signumber);
unsigned int alarm (unsigned intseconds);
int setitimer (int which,const structitimerval *value,struct itimerval *oldvalue);
Raise: Used to send a signal to the process itself. Successfully returns 0, failure returns-1.
#include <stdio.h>
#include <signal.h>
void func ();
void Main ()
{
charbuffer[100];
if (sig_err== signal (SIGINT,&FUNC))
{
printf ("signalerror!! \ n ");
Exit ( -1);
}
for (;;)
{
fgets (buffer,sizeof (buffer), stdin);
if (strcmp (buffer, "sigint\n") = = 0)
raise (SIGINT);
else
printf ("nocampare\n");
}
void func ()
{
printf ("hellofunc\n");
}
View a full set of articles: Http://www.bianceng.cn/Programming/C/201212/34807.htm