【发布时间】:2017-10-09 17:21:33
【问题描述】:
所以timeout 可用于设置进程/命令的最终时间限制,如here 和here 所述。例如,timeout 300 sleep 1000 将在 300 秒后返回提示,而不是 1000 秒。
但是有没有办法在进程仍在运行时即时修改此限制?所以这就是我要找的。
at time 0 : timeout 300 python long_run.py
at time 250 : <some way to extend the timeout limit by another 300 minutes or so>
我尝试了以下两种方法,但无法成功。
通过 GDB
我尝试使用 gdb 附加到 timeout 进程。它显示了以下调用堆栈,但我找不到可以更新其值以增加时间限制的变量。
(gdb) where
#0 0x00007f10b49f6e8c in __libc_waitpid (pid=15753, stat_loc=0x7fff0c799f30, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:31
#1 0x00000000004022d8 in ?? ()
#2 0x00007f10b4643f45 in __libc_start_main (main=0x401fc0, argc=4, argv=0x7fff0c79a0e8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fff0c79a0d8)
at libc-start.c:287
#3 0x0000000000402479 in ?? ()
0 0x00007f10b49f6e8c in __libc_waitpid (pid=15753, stat_loc=0x7fff0c799f30, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:31
31 ../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
(gdb) p *(stat_loc)
$2 = 4204240
通过 /proc/
我们可以在 /proc//limits 或 stat 文件中做些什么来更新 timeout 进程或子进程的超时限制。
【问题讨论】:
-
你有专门通过
timeout做吗? -
换句话说,在时间 250 发生了什么让您决定延长超时?您可以安排更长的超时时间开始,然后在时间 250,决定是提前终止进程,还是让它继续原来的超时时间。
-
最简单的可能是修改the source code for timeout。例如,您可以添加
-i选项来指定延长时间,并捕获信号SIGUSR1以调用调用timer_gettime和timer_settime的函数,通过添加延长时间来延长当前计时器值. -
如果这就是你所需要的,你可以做
kill -STOP pid_of_timeout它的孩子会继续运行。 -
kill -CONT pid将继续一个停止的进程。