Answer the question
In order to leave comments, you need to log in
Linux: echo $$ returns wrong PID, why?
I'm making a daemon in php (the daemon starts in the screen), you need to find out the PID of the daemon directly inside the script.
On Linux, there is an echo $$ command that returns the PID of the current process.
I write in the daemon:
// Узнаем PID текущего процесса
exec("echo $$", $pid);
echo "PID Демона: $pid[0]\n";
Answer the question
In order to leave comments, you need to log in
echo $$ returns the pid of the shell that exec launched. The fact that the number is next to the desired one is a coincidence.
To get the pid of your own process in php, there is a corresponding function getmypid
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question