参考
命令
p $_siginfo
测试
- 运行测试程序
$ gdb ./loop (gdb) start (gdb) c Continuing.
- 通过下面的用户进程向这个测试程序发送SIGUSER1(10)这个信号
$ echo $$ 497 $ id uid=1000(pengdl) gid=1000(pengdl) groups=1000(pengdl),4(adm),27(sudo) $ kill -10 770
- gdb这头会自动停下来
Program received signal SIGUSR1, User defined signal 1. main (argc=1, argv=0xfffffffff458) at ./loop.c:12 12 while(1);
- 查看最近收到的信号的信息
(gdb) set print pretty on (gdb) p $_siginfo $6 = { si_signo = 10, si_errno = 0, si_code = 0, _sifields = { _pad = {497, 1000, 0 <repeats 26 times>}, _kill = { si_pid = 497, si_uid = 1000 }, _timer = { si_tid = 497, si_overrun = 1000, si_sigval = { sival_int = 0, sival_ptr = 0x0 } }, _rt = { si_pid = 497, si_uid = 1000, si_sigval = { sival_int = 0, sival_ptr = 0x0 } }, _sigchld = { si_pid = 497, si_uid = 1000, si_status = 0, si_utime = 0, si_stime = 0 }, _sigfault = { si_addr = 0x3e8000001f1 }, _sigpoll = { si_band = 4294967296497, si_fd = 0 } } }
这个结构体的定义如下:
(gdb) ptype $_siginfo type = struct siginfo { int si_signo; int si_errno; int si_code; union { int _pad __attribute__ ((vector_size(28))); struct {...} _kill; struct {...} _timer; struct {...} _rt; struct {...} _sigchld; struct {...} _sigfault; struct {...} _sigpoll; } _sifields; } (gdb) ptype $_siginfo._sifields type = union { int _pad __attribute__ ((vector_size(28))); struct { __pid_t si_pid; __uid_t si_uid; } _kill; struct { int si_tid; int si_overrun; union sigval_t si_sigval; } _timer; struct { __pid_t si_pid; __uid_t si_uid; union sigval_t si_sigval; } _rt; struct { __pid_t si_pid; __uid_t si_uid; int si_status; __clock_t si_utime; __clock_t si_stime; } _sigchld; struct { void *si_addr; } _sigfault; struct { long si_band; int si_fd; } _sigpoll; }