I want to use a temp directory that will be unique to this build. How can I get the pid of my make command in the Makefile?
I tried:
TEMPDIR = /tmp/myprog.$$$$
but this seems to store TEMPDIR
as /tmp/myprog.$$
and then eval as a new pid for every command which refs this! How do I get one pid for all of them (I'd prefer the make pid, but anything unique will do).
Thanks in advance.
Compile the little C program here into a binary called start (or whatever you want), then run your program as ./start your-program-here arg0 arg1 arg2 ... Long story short, this will print the PID to stdout , then load your program into the process. It should still have the same PID.
Get PID : #!/bin/bash my-app & echo $! Save PID in variable: #!/bin/bash my-app & export APP_PID=$!
$$ means be interpreted as a $ by the shell. the $(UNZIP_PATH) gets expanded by make before being interpreted by the shell.
Try mktemp for creating unique temporary filenames. The -d
option will create a directory instead of a file.
TEMPFILE := $(shell mktemp)
TEMPDIR := $(shell mktemp -d)
Note the colon. (Editor's note: This causes make to evaluate the function once and assign its value instead of re-evaluating the expression for every reference to $(TEMPDIR).)
make
starts a new shell for each command it starts. Using bash (didn't check for other shells) echo $PPID
gives the parent process ID (which is make).
all: subtarget
echo $$PPID
echo $(shell echo $$PPID)
subtarget:
echo $$PPID
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With