1

Given two programs Program1.c and Program2.c, which are both executed separately as their own unrelated programs/processes:

Program1 knows the PID of Program2, and vise versa.

What C code (not shell commands) must both programs use to link their stdin/stdout to the other's stdout/stdin?

Nathan Darker
  • 141
  • 1
  • 9
  • Why not just use a socket? – o11c May 27 '19 at 00:15
  • Or a fifo/named pipe? – Shawn May 27 '19 at 00:35
  • Related: https://stackoverflow.com/questions/9689498/feedback-stdin-and-stdout-of-two-processes – S.S. Anne May 27 '19 at 00:47
  • 1
    Which o/s are you using? They'd each have to close their existing standard input and output and open mutually agreed connections — possibly Unix-domain sockets. – Jonathan Leffler May 27 '19 at 01:19
  • I don't know much about sockets, but know a pipe is more efficient/speedy for local inter-process communications, based on a quick google. As for namedpipes, i believe thats what stdon/stdout already is, and id rather use whats already there than coordinate new onesfor each separate program. Related question doesn't appear to be C, I want to link them within the sourcecode, not from a shell. As for OS, the target is linux, but im coding on windows and osx, so, the most universal option OR the answer for each os. Sometimes itll be implimented on arduino n stufflike that – Nathan Darker Jun 02 '19 at 22:05

1 Answers1

0

It's not possible (at least as far as I know). The memory for stdin and stdout is deallocated as soon as the program ends.

S.S. Anne
  • 15,171
  • 8
  • 38
  • 76
  • You're confusing `/proc/self/fd/` with `/dev/pts/`, and snooping the latter won't let the processes communicate, merely access the same data. – o11c May 27 '19 at 00:44
  • @o11c The question said "previously running processes". Should I just keep "it's not possible ..."? – S.S. Anne May 27 '19 at 00:45
  • It's certainly possible with a socket, named pipe, or even an anonymous pipe + snooping /proc//fd/, but OP hasn't answered the followup questions. – o11c May 27 '19 at 01:01