gpt4 book ai didi

linux - Signals Delivered Field of time 命令似乎不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:37:34 25 4
gpt4 key购买 nike

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

/usr/bin/time -v sleep 30

在另一个终端上,我执行了一个ps -a 并找到了sleep 进程的PID。现在我使用kill 向 sleep 进程发送一条消息- 1 PID 终止进程 sleep。由于 sleep 是按时间运行的,它列出了资源使用统计信息,如下所示

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,而不是因为未处理信号。

最佳答案

我正在使用这个程序:

#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

关于linux - Signals Delivered Field of time 命令似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14479636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com