unix环境高级编程_信号函数定义

四、kill, raise, alarmsleep

4.1kill函数

int kill(pid_t pid, int signo)

POSIX.1定义,将信号发送给进程或进程组,成功返回0,失败返回-1.

#pid > 0 将信号发送给进城IDpid的进程

#pid == 0 将信号发送给同进程组的其他所有进程

#pid < 0 将信号发送给其进程组ID等于pid绝对值的进程组的所有进程

#pid == -1 未定义

 

4.2raise函数

int raise( int signo )

ANSI C定义,将信号发送给进程自,成功返回0,失败返回-1.

 

4.3alarm函数

Unsigned int alarm(unsigned seconds)

使用alarm函数设置一个时间值,在将来的某个时刻时间值被超过后,产生SIGALARM信号。如果不忽略或不捕捉此信函,则其默认动作是终止该进程。

每个进程只能设置一个alarm。如果在调用alarm时,以前已为该进程设置过闹钟时间,而且它还没有超时,则该闹钟时间的余留时间值作为本次alarm函数调用的值返回。以前登记过得闹钟时间则被新值所替换。

 

4.4pause函数

Int pause(void);

Pause函数使调用进程挂起直至捕捉到一个信号。只有在执行了一个信号处理程序并从其返回时,pause才返回,在这种情况下,pause返回-1errno设置为EINTR.

 

4.5sigaction函数

int sigaction(int  signum,  const struct  sigaction  *act, 

struct  sigaction *oldact);

The sigaction()system call is used to change the action taken by a process  on

receipt of aspecific signal.

signum specifies  the signal  and  can be any valid signal except SIGKILL andSIGSTOP.

If act isnon-null, the new action for signal signum is installed from act. 

If oldact isnon-null, the previous action is saved in oldact.

 

4.6非局部转移函数

Sigsetjmpsiglongjmp,用在信号处理中的非局部转移。

非信号处理中使用setjmplongjmp来进行非局部转移。

 

4.7abort函数

Void abortvoid

此函数将SIGABRT信号发送给调用进程,进程不忽略此信号。

 

五、信号集

5.1 sigemptyset函数

int sigemptyset(sigset_t *set)

sigemptyset()initializes the signal set given by set to empty, with  all  signalsexcluded from the set.

 

5.2sigfillset函数

Int sigfillset(sigset_t* set)

sigfillset()initializes set to full, including all signals.

 

5.3sigaddset函数和sigdelset函数

int sigaddset(sigset_t *set, int signum)

int sigdelset(sigset_t *set, int signum)

sigaddset() andsigdelset() add and delete respectively signal signum from set.

 

 

5.4sigismember函数

int sigismember(const sigset_t *set, int signum);

sigismember()tests whether signum is a member of set.

 

5.5sigprocmask函数

int sigprocmask(int how, const sigset_t *set,sigset_t *oldset);

一个进程的信号屏蔽字规定了当前阻塞而不能传递给该进程的信号集。

调用此函数则可以检测或更改进程的信号屏蔽字。

 

5.6sigpending函数

int sigpending(sigset_t *set);

调用此函数返回调用进程被阻塞而不能递送和当前未决的信号集。该信号集通过set参数返回。

 

5.7sigsuspend函数

int sigsuspend(const sigset_t *mask);

sigsuspend()  temporarily replaces the signal mask of the calling process with the mask given bymask and then suspends the process until delivery of a signal whose action isto invoke a signal handler or to terminate a process.

If the  signal  terminates the process, then sigsuspend()does not return. 

If the signal is caught,  then sigsuspend()  returns  after the  signal  handler returns,  and the signal mask is restored to the state before the call to sigsuspend().

It is not possible to block SIGKILL orSIGSTOP;  specifying  these signals  in mask, has no effect onthe process

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值