How to run nohup and write its pid file in a single bash statement

后端 未结 3 1591
刺人心
刺人心 2021-01-30 08:26

I want to run my script in background and then write its pid file. I am using nohup to do this.

This is what i came up with,

nohup ./myprogram.sh > /d         


        
3条回答
  •  孤城傲影
    2021-01-30 09:18

    You already have one ampersand after the redirect which puts your script in background. Therefore you only need to type the desired command after that ampersand, not prefixed by anything else:

    nohup ./myprogram.sh > /dev/null 2>&1 & echo $! > run.pid
    

提交回复
热议问题