Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting last process' PID in Makefile

Tags:

makefile

pid

My Makefile look something like this:

setsid ./CppServer>daemon.log 2>&1 &
echo $!>daemon.pid

What I expect it to do is to store the PID of my_awesome_script in corresponding file. However there's nothing there. So where's the problem?

like image 861
Alex Avatar asked Apr 24 '11 01:04

Alex


People also ask

How do you find the current PID?

The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.

What is the command to get the PID of the most recent background command process?

jobs -p is another option which shows just the PIDs. To use this in a shell script, you'd have to process the output. @Phil To list pids only : jobs -p. To list pid of a certain job: jobs -p %3.


1 Answers

If your makefile really looks like this you will get an error, because I don't see any actual make syntax, just shell syntax. However, my crystal ball tells me that these two lines might be part of the recipe for a rule. If they are, you should realise how make executes recipes; for each line a separate subshell is created, in which that line's command is executed independently: your two commands don't know anything about each other's environment. If you want two commands to be executed in the same subshell, you should issue them as one line (using line continuation characters if necessary), or use make's ONESHELL directive.

like image 155
eriktous Avatar answered Sep 24 '22 08:09

eriktous