如何增加进程 运行 'timeout' 命令的超时限制
How to increase timeout limit for a process running with 'timeout' command
因此 timeout
可用于设置进程/命令的最终时间限制,如前所述 here and here 。例如,timeout 300 sleep 1000
将 return 在 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)
= 4204240
通过/proc/
我们可以在 /proc//limits 或 stat 文件中做些什么来更新 timeout
进程或子进程的超时限制。
根据 Mark Plotnick 非常有帮助的评论收敛问题的解决方案。
解决方案 1
kill -STOP
停止进程并 kill -CONT
恢复它。
因此 kill -STOP pid_of_timeout
将停止超时/计时器 运行ning,而子进程将继续 运行ning。我们可以在需要时通过 kill -CONT pid_of_timeout
恢复计数器
这意味着在计时器中添加一个延迟,比如 50,下面就可以了。
kill -STOP pid_of_timeout ; sleep 50 ; kill -CONT pid_of_timeout
解决方案 2
将超时进程附加到gdb。它将冻结超时过程。完成后从 GDB 分离。
解决方案 3
修改source code of timeout,编译并运行它而不是系统"timeout"进程。
因此 timeout
可用于设置进程/命令的最终时间限制,如前所述 here and here 。例如,timeout 300 sleep 1000
将 return 在 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)
= 4204240
通过/proc/
我们可以在 /proc//limits 或 stat 文件中做些什么来更新 timeout
进程或子进程的超时限制。
根据 Mark Plotnick 非常有帮助的评论收敛问题的解决方案。
解决方案 1
kill -STOP
停止进程并 kill -CONT
恢复它。
因此 kill -STOP pid_of_timeout
将停止超时/计时器 运行ning,而子进程将继续 运行ning。我们可以在需要时通过 kill -CONT pid_of_timeout
这意味着在计时器中添加一个延迟,比如 50,下面就可以了。
kill -STOP pid_of_timeout ; sleep 50 ; kill -CONT pid_of_timeout
解决方案 2
将超时进程附加到gdb。它将冻结超时过程。完成后从 GDB 分离。
解决方案 3
修改source code of timeout,编译并运行它而不是系统"timeout"进程。