Capturing the PID of a background process started by a Makefile

前端 未结 2 770
花落未央
花落未央 2021-01-02 15:39

I have a Makefile that starts a Django web server. I would like the server to be started in the background, with the PID saved to a file.

My recipe looks like this:<

相关标签:
2条回答
  • 2021-01-02 15:49

    If Make gives you too much trouble, you can always have the target launch an sh script; in that script, launch the process, background, and then output the pid to a file.

    0 讨论(0)
  • 2021-01-02 15:53

    Just leave a single ampersand, without a semicolon after it:

    run: venv
        @"${PYTHON}" "${APP}/manage.py" runserver 80 & echo "$$!" > "${LOGDIR}/django.pid"
    

    Ampersand acts as command separator in the same way as a semicolon:

    <command> & <command>
    
    0 讨论(0)
提交回复
热议问题