tags:

views:

149

answers:

4

Hi! newb here. I am trying to make a c++ program that will read from a named pipe created by python. My problem is, the named pipe created by python uses os.getpid() as part of the pipe name. when i try calling the pipe from c++, i use getpid(). i am not getting the same value from c++. is there a method equivalent in c++ for os.getpid?

thanks!

edit:

sorry, i am actually using os.getpid() to get the session id via ProcessIDtoSessionID(). i then use the session id as part of the pipe name

A: 

The standard library does not give you anything other than files. You will need to use some other OS specific API.

dirkgently
+4  A: 

You don't get same proccess IDs because your python program and c++ programs are run in different proccesses thus having different process IDs. So generally use a different logic to name your fifo files.

kyku
i see. thanks. i was using os.getpid() as a parameter to pywin32's ProcessIDtoSessionID to get the session ID.i will try to use a different method. thanks again!
maranas
+2  A: 

You won't get the same value if you're running as a separate process as each process has their own process ID. Find some other way to identify the pipe.

Ignacio Vazquez-Abrams
A: 

You cannot easily retrieve the Python interpreter's PID from your C++ program.

Either assign the named pipe a constant name, or if you really need multiple pipes of the same Python program, create a temporary file to which the Python programs write their PIDs (use file locking!) - then you can read the PIDs from the C++ program.

AndiDog