LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   get the PID of a separate process (no parent-child relationship) (https://www.linuxquestions.org/questions/linux-software-2/get-the-pid-of-a-separate-process-no-parent-child-relationship-410846/)

arunj 02-02-2006 08:31 AM

get the PID of a separate process (no parent-child relationship)
 
Hi friends,

Can anybody plz tell me how I can get the PID of a concurrent process from a second process which does not have any parent-child relationship between them? Both processes have only one instance and one process knows the name of the other process.
Plz give me a solution other than using the system() function. Is there any system call that can help me?

Thanks,
Arun

trickykid 02-02-2006 08:37 AM

pstree might help..

arunj 02-02-2006 09:24 AM

But pstree too is a shell command (as far as I know). I need some function that will help me retrieve the PID of the process concerned. I have only one one instance of each process running. So in this case, I may make each process name unique.

rimkus 02-02-2006 11:36 AM

It is hokey but have the process write its pid to a file and read the file. What language are you using?
You might try putting the pid in shared memory.

sundialsvcs 02-02-2006 12:31 PM

Usually, "pid-files" is what I see most processes do. They write their PID to a file on startup, and remove it when they shut down.

A shared-memory segment would also be a good idea.

It occurs to me that you could also walk through the /proc "directory" ...

arunj 02-03-2006 12:14 AM

Thanks rimkus and sundialsvcs!

"pid-files" is really a good idea if the processes automatially (using kernel intervention) do that. If possible, please gimme some more information while I'm myself diving into it. I'm also going through /proc directory to find this out. I'm using the gcc library only. In fact, my work is related to Embedded Linux and I'm facing a lot of memory constraints because of the design of the hardware I'm working on.

Thanks once again,

Arun

arunj 02-03-2006 01:50 AM

Let me explain. Right now I want to send a message from one process to another process (name known, right now, only a single instance) which will lead to the invocation of some function by the second process. The two processes are unrelated. If this isn't possible without handling the pid and other info by a third process (which is going to manage), I have to make arrangements for information passing between the processes using the third one. I don't want to use shared memory right now and the best alternative is passing pointers. How can I pass these pointers between the proceses without any copying of data (i.e., the pointers will be accessible to all the processes)?

Thanks,
Arun


All times are GMT -5. The time now is 09:30 PM.