1

我一直在试验时间命令(/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。在那种情况下, Signals Delivered 字段仍然为 0。这让我得出结论 Signals Delivered 字段为 0 ,而不是因为未处理信号。

4

2 回答 2

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
于 2013-01-23T13:03:31.403 回答
0

time 使用 wait4 系统调用。我发现一件事是 struct rusage的某些字段仍未维护。ru_nsignals 是 struct rusage中的一个这样的字段。有关详细信息,请参阅此问题的正确答案

于 2013-01-23T14:07:04.190 回答