将生成的进程的PID保存在Makefile中 [英] saving PID of spawned process within a Makefile

查看:95
本文介绍了将生成的进程的PID保存在Makefile中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个Makefile规则,因此:

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`

这是start.sh脚本:

here is the start.sh script:

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

NB server.py必须在bin目录中运行

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

我想在启动规则中实现start.sh的功能,我尝试了很多事情,但似乎无法获得PID.

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.

推荐答案

我不知道您会在哪里卡住. 怎么了

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

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

?

您还可以将pidfile设为目标和依赖项:

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

这篇关于将生成的进程的PID保存在Makefile中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆