It seems obviose, but I surprised to be not able to get it!
In bash, expected to get a current process ID by '$$'
So, if I ran backgroung any stuff and try from there get that process ID I would expect to have the same number as I have reported on foregroung screen, when I have started that background!
But it is not right!
See, the backgroung process return the PID of parent process?! - 14001, while I would expect the 8106 ?!?!
How I should get the '8106' from inside of the curved brases?
The reason is that I need to run concurently many processes, which should use the same functions that need to use own files. I need separate files between processes and timestamp is not usefull.
I have plan to use the PID but..!!!
What I understand wrong about PIDs?
How I could get PID of any backgroung process from that process?
Does anyone know the way to get any process PID inside of that process?
Ok, example:
Exist a function FUNK that in processing create temporary file and call other functions that use that file.
From process-1 I start background processed B1, B2, B3
Each call the FUNC
I need to be able to separate the files that FUNC will create.
That why I need the PID of each process INSIDE of that process! NOT in the parent process where B1,B2,B3 has been started.
I need the FUNC be able to get the B1 PID when it is running in B1, B2 PID when the FUNC is called in B2 and B3 ... - the same.
(I do not see a reason to reply on 'very constructive' responses as 'if I ever read manual', or on pretention that I expect the same PID, or on advise to get it by parent process )
cfajohnson - if you mean that the $BASHPID should give me the current PID - that is not clear from your statement.
Although I have check that, and my shell does not have this variable defined.
Also I have not found this variable in bash manual.
What would be another way (than $BASHPID) to get a background PID for function that is running in that backgroung process?
Is there any solution for, seems, so simple task?!?