Kill process after a given time bash?

后端 未结 5 1690
被撕碎了的回忆
被撕碎了的回忆 2021-02-01 03:23

I have a script that tries to make a DB connection using another program and the timeout(2.5min) of the program is to long. I want to add this functionality to the script.

5条回答
  •  青春惊慌失措
    2021-02-01 03:41

    There's a GNU coreutils utility called timeout: http://www.gnu.org/s/coreutils/manual/html_node/timeout-invocation.html

    If you have it on your platform, you could do:

    timeout 5 CONNECT_TO_DB
    if [ $? -eq 124 ]; then
        # Timeout occurred
    else
        # No hang
    fi
    

提交回复
热议问题