0

I'm using c language in Linux. I have set up code to create a bidirection pipe between a child process and a parent process. I'm able us the pipe for bidirectional communication. However, I'm supposed to use the pid, process id, of the child process in order to send an EOF to the child process and thus close the pipe used to send input to the child process. This is supposed to be done with just the pid, from within the parent process. Do I have a way to do this? I've been looking around and I haven't figured this out.

I'm using the functions pipe(), fork(), execl(), etc. for this program.

Additionally, it's for a command shell: execl("/bin/sh", "sh", "-c", command, NULL);

This might be my clue.

Thanks for any help!

...John

John Alway
  • 65
  • 10
  • The read end of the pipe will get an EOF when the write end is closed. *with just the pid*. Though I'm not sure what that means. Suspect you are either misunderstanding the requirements or not describing that clearly to us. Suggest you provide the original task wording. – kaylum Mar 16 '21 at 00:27
  • Here is a description of the function. "close_child_process() closes the stream used to send input to the child 'pid'. This sends an EOF to the child process which allows it to end the stream." Here is the prototype: int close_child_process(pid_t pid){ } ... So, with that function and the passed in pid parameter I'm supposed to shutdown the stream. – John Alway Mar 16 '21 at 00:40
  • Additionally, it's using a shell command thus: execl("/bin/sh", "sh", "-c", command, NULL); I just saw something about "ctrl D" to send an EOF. In other words, the child process is a command shell command. So, maybe that's the key? – John Alway Mar 16 '21 at 00:47
  • 1
    You aren't really interpreting the question correctly IMHO. Just because the function takes a pid does not mean you need to use the pid directly to send the EOF. It even tells you that close will send the EOF. You don't provide enough info so it is difficult to guess the full structure of the program. But it sounds like you just need to use the pid to find the pipe that corresponds to that child process and call close on it. – kaylum Mar 16 '21 at 00:59
  • @kaylum -- Okay, maybe you're right. I just thought maybe there was some standard function that would allow me to use the pid to shutdown a stream. That's what I was wondering. Maybe there isn't. If not, then I can definitely find a work around. – John Alway Mar 16 '21 at 01:11
  • Will you ever have multiple, simultaneous child processes? – that other guy Mar 16 '21 at 01:42
  • @the other guy -- Yes, there will be up to 8 running. – John Alway Mar 16 '21 at 02:25

0 Answers0