linux下信号注册

fenglinngu123 2012-06-05 11:25:40
linux下 信号量通信,我不想用系统的信号,怎么注册一个新的信号。
...全文
149 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
localxiao 2012-06-05
  • 打赏
  • 举报
回复
做不到,不是windows,你还可以发送自定义消息

最多,看楼上
justkk 2012-06-05
  • 打赏
  • 举报
回复
不能自己添加吧
可以使用 SIGUSR1 SIGUSR2
qq120848369 2012-06-05
  • 打赏
  • 举报
回复
[User:root Time:17:13:28 Path:/home/liangdong/c]$ make
gcc -g -I./include -c -o src/main.o src/main.c
.gcc -o output src/main.o -lpthread -lm -lz
Makefile done.
[User:root Time:17:13:29 Path:/home/liangdong/c]$ ./output
[34-64]
[User:root Time:17:13:29 Path:/home/liangdong/c]$ kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
[User:root Time:17:13:32 Path:/home/liangdong/c]$ ./output
[34-64]
[User:root Time:17:13:42 Path:/home/liangdong/c]$ cat src/main.c
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

int main(int argc, char* const argv[]) {
printf("[%u-%u]\n", SIGRTMIN, SIGRTMAX);
return 0;
}


自己看吧,kill -l里的序号就是信号的值。
qq120848369 2012-06-05
  • 打赏
  • 举报
回复
       This header shall also declare the macros SIGRTMIN and SIGRTMAX, which evaluate to integer expressions, and specify a range of signal numbers  that  are
reserved for application use and for which the realtime signal behavior specified in this volume of IEEE Std 1003.1-2001 is supported. The signal num-
bers in this range do not overlap any of the signals specified in the following table.

The range SIGRTMIN through SIGRTMAX inclusive shall include at least {RTSIG_MAX} signal numbers.

It is implementation-defined whether realtime signal behavior is supported for other signals.

This header also declares the constants that are used to refer to the signals that occur in the system. Signals defined here begin with the letters SIG.
Each of the signals have distinct positive integer values. The value 0 is reserved for use as the null signal (see kill()). Additional implementation-
defined signals may occur in the system.

The ISO C standard only requires the signal names SIGABRT, SIGFPE, SIGILL, SIGINT, SIGSEGV, and SIGTERM to be defined.

The following signals shall be supported on all implementations (default actions are explained below the table):

Signal Default Action Description
SIGABRT A Process abort signal.
SIGALRM T Alarm clock.
SIGBUS A Access to an undefined portion of a mem-
ory object.
SIGCHLD I Child process terminated, stopped,
or continued.
SIGCONT C Continue executing, if stopped.
SIGFPE A Erroneous arithmetic operation.
SIGHUP T Hangup.
SIGILL A Illegal instruction.
SIGINT T Terminal interrupt signal.
SIGKILL T Kill (cannot be caught or ignored).
SIGPIPE T Write on a pipe with no one to read it.
SIGQUIT A Terminal quit signal.
SIGSEGV A Invalid memory reference.
SIGSTOP S Stop executing (cannot be caught or
ignored).
SIGTERM T Termination signal.
SIGTSTP S Terminal stop signal.
SIGTTIN S Background process attempting read.
SIGTTOU S Background process attempting write.
SIGUSR1 T User-defined signal 1.
SIGUSR2 T User-defined signal 2.
SIGPOLL T Pollable event.
SIGPROF T Profiling timer expired.
SIGSYS A Bad system call.
SIGTRAP A Trace/breakpoint trap.
SIGURG I High bandwidth data is available at a
socket.
SIGVTALRM T Virtual timer expired.
SIGXCPU A CPU time limit exceeded.
SIGXFSZ A File size limit exceeded.


SIGRTMIN and SIGRTMAX, which evaluate to integer expressions, and specify a range of signal numbers that are
reserved for application use and for which the realtime signal behavior specified in this volume of IEEE Std 1003.1-2001 is supported.

这个范围里的你都可以用,属于实时信号,相同信号可以排队。

69,369

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧