saving PID of spawned process within a Makefile

Chris Camacho

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.

reinierpost

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I get the pid of a spawned process using pexpect?

From Dev

How do I get the pid of a spawned process using pexpect?

From Dev

pid of a process created by python subprocess.Popen(shell=True) is not the pid of the spawned shell

From Dev

PyQt4 QProcess.startDetached() - can't get return value and PID of spawned process

From Dev

How to start process at foreground saving it's pid to a file?

From Dev

Interaction with spawned process in Scala

From Dev

Pass a packed JS file within an asar package to a spawned node child process

From Dev

Pass a packed JS file within an asar package to a spawned node child process

From Dev

Find pid of each process invoked within shell script

From Dev

Processes spawned on connected nodes get same PID

From Dev

Processes spawned on connected nodes get same PID

From Dev

Supervisord error "child process was not spawned"

From Dev

mount fails from spawned process

From Dev

Killing a process spawned by another thread

From Dev

killing the master process spawned by an at command

From Dev

How can a process be blocking another process (that it spawned)?

From Dev

How to pass PID of one process to another process within the same shell script?

From Dev

os.kill not working on spawned process

From Dev

spawned process in node.js exiting immediately

From Dev

How to detect if a Node spawned process is still running?

From Dev

Visual Studio Code - Debugging a spawned process

From Dev

Testing captured IO from a spawned process

From Dev

Read stdout of spawned process that is waiting for input

From Dev

What happens to imports when a new process is spawned?

From Dev

Can't send anything to spawned Erlang process

From Dev

Not receiving stdout from nodejs spawned process

From Dev

Shell spawned backgrounded process is still hanging

From Dev

Kill process spawned by ssh when ssh dies

From Dev

Finding process name by PID

Related Related

  1. 1

    How do I get the pid of a spawned process using pexpect?

  2. 2

    How do I get the pid of a spawned process using pexpect?

  3. 3

    pid of a process created by python subprocess.Popen(shell=True) is not the pid of the spawned shell

  4. 4

    PyQt4 QProcess.startDetached() - can't get return value and PID of spawned process

  5. 5

    How to start process at foreground saving it's pid to a file?

  6. 6

    Interaction with spawned process in Scala

  7. 7

    Pass a packed JS file within an asar package to a spawned node child process

  8. 8

    Pass a packed JS file within an asar package to a spawned node child process

  9. 9

    Find pid of each process invoked within shell script

  10. 10

    Processes spawned on connected nodes get same PID

  11. 11

    Processes spawned on connected nodes get same PID

  12. 12

    Supervisord error "child process was not spawned"

  13. 13

    mount fails from spawned process

  14. 14

    Killing a process spawned by another thread

  15. 15

    killing the master process spawned by an at command

  16. 16

    How can a process be blocking another process (that it spawned)?

  17. 17

    How to pass PID of one process to another process within the same shell script?

  18. 18

    os.kill not working on spawned process

  19. 19

    spawned process in node.js exiting immediately

  20. 20

    How to detect if a Node spawned process is still running?

  21. 21

    Visual Studio Code - Debugging a spawned process

  22. 22

    Testing captured IO from a spawned process

  23. 23

    Read stdout of spawned process that is waiting for input

  24. 24

    What happens to imports when a new process is spawned?

  25. 25

    Can't send anything to spawned Erlang process

  26. 26

    Not receiving stdout from nodejs spawned process

  27. 27

    Shell spawned backgrounded process is still hanging

  28. 28

    Kill process spawned by ssh when ssh dies

  29. 29

    Finding process name by PID

HotTag

Archive