Linux下C编程:raise
信号的发送的要害是使系统知道向哪个历程发送信号以及发送什么信号。个中要留意的是可否向某一历程发送某个特定的信号是和用户的权限密切相关的。譬喻,只有系统打点员才气发送SIGKILL信号终止历程。
用于发送信号的系统挪用。
#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:用于向历程自身发送信号。乐成返回0,失败返回-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");
}

查察全套文章:http://www.bianceng.cn/Programming/C/201212/34807.htm