![]() |
![]() HP OpenVMS Systemsask the wizard |
![]() |
The Question is: Is there any way to change a C Run Time Library pipe so it would be more like a mailbox in that it's unbuffered by stdio in the child without changing the child program? Or is there a way to cause mailboxes to work more like pipes and only send an EOF wh en the last channel on the mailbox is closed? Note: That should be the last writer channel as the last channel is usually the reader channel. I am currently working on a way to spawn a child process and have the standard input, output, and error redirected back to the parent through some means. Also I would like to do it in a POSIX standard way. Previously I used a pipe and everything was wor king correctly except that the child processes buffer all the standard output through the pipe. I realize using setvbuf in the child would fix this problem but the spawn routines have to be generic enough to spawn any program or script written by a numbe r of people. I then went to using a temporary mailbox and creating 2 channels(one reader, one writer) to that mailbox via open() to simulate a pipe. This approach also works fairly well but we run into problems when the spawned process also spawns a pro cess which inherits the stdin, stdout, and stderr file descriptors. When this sub-sub-process exits it closes all it's standard descriptors, like all programs should, which causes an EOF to be written into the mailbox. This causes the main process to wa ke up and think that it's child has finished when it really hadn't. If I ignore the EOF then I get the rest of the output. The problem with ignore the EOF is there isn't a way for me to know how many EOFs I need to ignore, and if I read after getting th e last EOF I will block forever on that read since no new processes will be writting to that mailbox. I am aware of using lib$spawn or sys$creprc, but if I go down that path then I loose a lot of the functionality and ease of use of the vfork/exec/decc$set_child_streams approach. Also realize I have to support Unix as well, but can seperate the code for VMS from the code from UNIX. Also I'm currently using read() and write() to communicate on the mailbox from the parent process, yet have no control as to how the child process would send data via stdout. Pipes kind of work and mailboxes also kind of wor k. I've read the C RTL documentation extensively and most of the system services documentation but haven't been able to find any way to control either the child's default behavior of buffering on pipes or the behavior of sending EOF everytime a channel i s close on a mailbox. I suspect that there has to be a way of controlling this, but have yet to find it in the documentation. Actually from rereading my question I thought of a possible solution. I could check the number of channels assigned to the mailbox and stop ignoring EOFs once there is only 1 channel assigned to the mailbox. I'd still like to know if there is a more eleg ant way to fix this problem so my question still stands. Thank you for your help. The Answer is : Use a mailbox directly -- this is the most common means through which a server subprocess reads and writes commands via a mailbox.
|