saving PID of spawned process within a Makefile

只谈情不闲聊 提交于 2019-11-29 09:37:58

问题


I currently have a Makefile rule thus:

start:
    ./start.sh

which starts a very simple server needed as part of the build process. I have another rule for stopping the server:

stop:
    kill `cat bin/server.PID`

here is the start.sh script:

#!/bin/bash
cd bin
python server.py &
echo $! > server.PID

NB server.py must be run from within the bin directory

I'd like to implement the functionality of start.sh within the start rule, I've tried numerous things but can't seem to get the PID.


回答1:


I don't understand where you're getting stuck. What's wrong with

start:
    cd bin && { python server.py & echo $$! > server.PID; }

?

You can also make the pidfile a target and dependency:

start: server.PID

server.PID:
    cd bin && { python server.py & echo $$! > $@; }

stop: server.PID
    kill `cat $<` && rm $<

.PHONY: start stop


来源:https://stackoverflow.com/questions/23366112/saving-pid-of-spawned-process-within-a-makefile

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!