Topic
1 reply Latest Post - ‏2002-09-29T21:08:51Z by SystemAdmin
SystemAdmin
SystemAdmin
2364 Posts
ACCEPTED ANSWER

Pinned topic Create new FD for read & write

‏2002-03-26T21:40:26Z |
Hello,

Please have a look at the requirement.

LINUX
How to open a new file descriptor in Read/Write mode without
binding with an object like file, STDIN . etc .,?

We have a API call that creates a new Process in it? To capture
all the streams of the new process. We pass the fd to library
which in turn does the dup2 operation. It collects only one file
descriptor as a Parameter and it does dup2 to all 3 streams(IN, OUT, ERR).

I'll use the same descriptor to communicate with the new Process.

To achieve this i did "pipe" and i sent the fd[1] (i.e., for writing) as the
parameter.
But it is failing to use the same file descriptor for read.

I think we can achieve this if we create a new file descriptor in read write
mode with out binding with any object.

If U have any way of implementing this. pls let us know

regards,
Johinth
Updated on 2002-09-29T21:08:51Z at 2002-09-29T21:08:51Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    2364 Posts
    ACCEPTED ANSWER

    RE: Create new FD for read & write

    ‏2002-09-29T21:08:51Z  in response to SystemAdmin
    I'm not sure if you're having trouble with the pipe or with the fd you want to
    pass, but I suspect the pipe. Many pipe imnplementations are half duplex and a
    programmier assuming this leads to more portable code. The pipe() call returns
    two file descriptors, one for writing and one for reading. If a process then
    does a fork() to create a child the parent will typically close the read end of
    the pipe while the child will close the write end of the pipe and this makes an
    IPC channel from parent to child. If you want a return path, you should call
    pipe() twice before calling fork(). In this case the parent closes the write
    end of the second pipe and the child closes the read end and the second pipe
    can then be used to communicate back to the parent from the child.

    Once you have the pipes you can pass open file descriptors. The book "Advanced
    Programming in the UNIX Environment" by W. Richard Stevens has a couple of
    chapters on interprocess communications that describe this process quite well.
    You can also check the pipe() syntax on Linux using info pipe.
    Updated on 2002-09-29T21:08:51Z at 2002-09-29T21:08:51Z by SystemAdmin