已发送的信号时间字段命令似乎不起作用

时间:2013-01-23 12:22:26

标签: linux bash

我一直在尝试使用time命令(/ usr / bin / time)。我让时间命令运行如下

/usr/bin/time -v sleep 30

在另一个终端上我做了一个ps -a并找到了sleep进程的PID。现在我使用kill -1 PID向睡眠发送一条消息,终止了进程的睡眠。睡眠是在时间的关系上运行的,它列出了资源使用统计数据如下

Command being timed: "sleep 30"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:21.81
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 2160
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 180
Voluntary context switches: 2
Involuntary context switches: 2
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

但令我惊讶的是,Signals Delivered字段为0!怎么可能?

编辑:

我尝试使用以下脚本而不是sleep 30

trap "echo Hello" 1 2
sleep 30

现在,我将上述脚本计时并向其发送信号1和2。在这种情况下,信号传递字段仍为0.这使我得出结论,信号传递字段为0,而不是因为信号未被处理。

2 个答案:

答案 0 :(得分:0)

我正在使用这个程序:

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>

volatile unsigned int counter=0;

void exithandler(int signum)
{
_exit(1);
}

void ignorehandler(int signum)
{
counter += signum;
}

int main(int argc, char **argv)
{

int delay;

signal ( SIGHUP, ignorehandler );
signal ( SIGQUIT, exithandler );
for (delay = atoi(argv[1] ); delay > 0; ) {
        delay = sleep( delay);
        }

printf("Counter=%u\n", counter);
return 0;
}

,我得到了类似的结果(显然是在11个SIGHUPS之后):

Plasser@pisbak>$ Counter=11
Command being timed: "./mysleep 20"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:22.56
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1856
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 163
Voluntary context switches: 13
Involuntary context switches: 1
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
[1]+  Done                    /usr/bin/time -v ./mysleep 20
Plasser@pisbak>$ man getrusage

答案 1 :(得分:0)

时间利用了wait4系统调用。我发现一些结构 rusage 的字段仍未维护。 ru_nsignals是struct rusage 中的一个这样的字段。 有关详细信息,请参阅此question

的正确答案