• linux bash timeout


     

    http://www.digitalinternals.com/unix/unix-linux-run-command-with-timeout/500/

     

    There are two ways to send a SIGKILL signal to the process from the timeout utility. The first way is by specifying the default signal to be sent using the following syntax.

    $ timeout -s KILL 1m /path/to/slow-command arg1 arg2

    The second way is to first send the SIGTERM after the initial timeout. Then, wait for another timeout and send a SIGKILL to the process if it’s still running. This can be done using the following syntax.

    $ timeout -k 30 1m /path/to/slow-command arg1 arg2

    The process is sent a SIGTERM signal after 60 seconds. If it is still running, then a SIGKILL signal is sent after another 30 seconds.

    In the event that the timeout utility is not available, the below 1-liner can be used as an alternative.

    $ /path/to/slow-command arg1 arg2 & sleep 60; kill $!

    The slow-command is started as a background process. The sleep command will then pause till the timeout duration. In our case, it will sleep for 60 seconds. Once 60 seconds has elapsed, the kill command will send a SIGTERM signal to the slow-command process. The ‘$!‘ shell variable will give the PID of the last background job.

  • 相关阅读:
    Dragon Balls_并查集
    Farm Irrigation_并查集||dfs
    The trouble of Xiaoqian_多重背包&&完全背包
    Difference Is Beautiful
    Bone Collector II_第k大背包
    Dividing_多重背包
    Milk
    coins_多重背包
    钱币兑换问题_完全背包&&拆分&&母函数
    多项式链表多项式相加
  • 原文地址:https://www.cnblogs.com/itech/p/7306967.html
Copyright © 2020-2023  润新知