加入收藏 | 设为首页 | 会员中心 | 我要投稿 威海站长网 (https://www.0631zz.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Linux > 正文

Signal Handling--ref

发布时间:2021-01-25 08:01:09 所属栏目:Linux 来源:网络整理
导读:signal is a software interrupt delivered to a process. The operating system uses signals to report exceptional situations to an executing program. Some signals report errors such as references to invalid memory addresses; others report asy

The followingerrnoerror conditions are defined for this function:

EINVAL
Thesignumargument is an invalid or unsupported number.
EPERM
You do not have the privilege to send a signal to the process or any of the processes in the process group named bypid.
ESCRH
Thepidargument does not refer to an existing process or group.
intkillpg(intpgid,intsignum)
This is similar tokill,but sends signalsignumto the process grouppgid. This function is provided for compatibility with BSD; usingkillto do this is more portable.

kill,the callkill (getpid (),sig)has the same effect asraise (sig).

kill

killto send signals to any random process. These are intended to prevent antisocial behavior such as arbitrarily killing off processes belonging to another user. In typical use,killis used to pass signals between parent,child,and sibling processes,and in these situations you normally do have permission to send signals. The only common execption is when you run a setuid program in a child process; if the program changes its real UID as well as its effective UID,you may not have permission to send a signal. Thesuprogram does this.

`root'),or the real or effective user ID of the sending process must match the real or effective user ID of the receiving process. If the receiving process has changed its effective user ID from the set-user-ID mode bit on its process image file,then the owner of the process image file is used in place of its current effective user ID. In some implementations,a parent process might be able to send signals to a child process even if the user ID's don't match,and other implementations might enforce other restrictions.

SIGCONTsignal is a special case. It can be sent if the sender is part of the same session as the receiver,regardless of user IDs.

killfor Communication

SIGUSR1andSIGUSR2signals are provided for. Since these signals are fatal by default,the process that is supposed to receive them must trap them throughsignalorsigaction.

SIGUSR1signal,using thekillfunction.

#include 
#include 
#include 
#include 

/ When a SIGUSR1 signal arrives,set this variable. /
volatile sig_atomic_t usr_interrupt = 0;

void
synch_signal (int sig)
{
usr_interrupt = 1;
}

(编辑:威海站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读