tnx1991 tnx1991 - 1 year ago 73
Linux Question

Passing file descriptor from one program to another on the same host using UNIX sockets

I have two prgrams lets say prog1 and prog2. I am opening a file with prog1 and doing some operations
on it. Now without closing the file in prog1 i am sending its file descriptor to prog2 using unix
sockets which then does some operations in it.

Though i get the same descriptor i passed in prog1 but doing a fstat() on the fd recieved in prog2
throws an error saying Bad file descriptor. I have opened the file in prog1 with corerct permissions
that is read and write for all, still i get an error.

Why is it happening so. If my way of passing a file descriptor is wrong then please suggest a correct

R.. R..
Answer Source

I believe this site has what you're looking for:

There's also information in Linux's man 7 unix on using SCM_RIGHTS and other features of Unix sockets.

Fix for broken link:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download