How can I get a stdin process using a process id?

I know that I can get the stdin process to use a subprocess in python , for example:

 import subprocess f = subprocess.Popen('python example.py',stdin=subprocess.PIPE) f.stdin.write('some thing') 

but I want to know only the pid that I want to write to the stdin process, how can I do this?

+7
source share
1 answer

Just write to /proc/PID/fd/1 :

 import os.path pid = os.getpid() # Replace your PID here - writing to your own process is boring with open(os.path.join('/proc', str(pid), 'fd', '1'), 'a') as stdin: stdin.write('Hello there\n') 
+11
source

All Articles