简体   繁体   中英

How to increase timeout limit for a process running with 'timeout' command

So timeout can be used to set the ultimate time limit on a process / command as mentioned here and here . For example, timeout 300 sleep 1000 will return to prompt after 300 seconds itself instead of 1000.

But is there any way to modify this limit on the fly while process is still running ? So this is what I am looking for.

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>

I tried following two ways but couldn't make it work.

Through GDB

I tried to attach to timeout process with gdb. It showed following call stack but I couldn't find a variable whose value I could update to increase time limit.

(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

Through /proc/

Is there anything we can do in /proc//limits or stat file to update timeout limit for timeout process or child process.

Converging the solution to question based on Mark Plotnick 's much helpful comments.

Solution 1

kill -STOP stops a process and kill -CONT resumes it.

So kill -STOP pid_of_timeout will stop the timeout / timer running while child process will continue running. We can resume the counter when we want by kill -CONT pid_of_timeout

This means to add a delay of, say 50 in the timer, following will do the trick.

kill -STOP pid_of_timeout ; sleep 50 ; kill -CONT pid_of_timeout

Solution 2

Attach the timeout process to gdb. It will freeze timeout process. Detach from GDB when done.

Solution 3

Modify the source code of timeout , compile and run it instead of system "timeout" process.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM