Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はプロセスのstdin使用サブプロセスを次のpythonように取得できることを知っています:
stdin
python
import subprocess f = subprocess.Popen('python example.py',stdin=subprocess.PIPE) f.stdin.write('some thing')
しかし、プロセスに書き込みたいpidだけを知りたいのですが、stdin どうすればこれを行うことができますか?
に書くだけ/proc/PID/fd/1です:
/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')