Call a function using nohup

前端 未结 6 1717
滥情空心
滥情空心 2020-12-10 10:59

I am trying to call a function using nohup like this:

function1(){
    while true 
    do
        echo \"function1\"
        sleep 1
    done
}
         


        
6条回答
  •  萌比男神i
    2020-12-10 11:54

    nohup applies to commands and not to script functions.

    For example, the script (say func.sh) that contains function1() should call the function-:

    function1(){
        while true 
        do
            echo "function1"
            sleep 1
        done
    
    }
    
    function1
    

    Now call the script func.sh with nohup in the background-:

    nohup ./func.sh &
    

    If you need to disable the hangup signal from within the script use the shell built-in trap. The example ignores SIGHUP but can be used to ignore others (e.g. SIGINT).

    trap "" HUP   # script will ignore HANGUP signal
    

提交回复
热议问题