Share socket fd between two processes


 
Thread Tools Search this Thread
Top Forums Programming Share socket fd between two processes
# 1  
Old 10-20-2010
Share socket fd between two processes

Hello every one i am implementing client server program.To handle multiple fds of client in server i used poll function.But this poll not able to access socket fd from other process.How can i share socket fd between two process.

Please Help me,Thanks in advance.
# 2  
Old 10-20-2010
When a program fork()s, its file descriptors get inherited by the parent - not sure if this is the only way, but it's certainly a way.
# 3  
Old 10-20-2010
Some web servers have passed accepted socket fd through sockets or pipes to pre-spawned helper processes on the same host. There is a procedure for turning the fd into a portable reference upstream and then back to a new fd on the downstream end. I will Google.

---------- Post updated at 01:47 PM ---------- Previous update was at 01:46 PM ----------

pass fd through pipe OR socket - Google Search

portlisten: passing socket file descriptors through sockets

---------- Post updated at 01:52 PM ---------- Previous update was at 01:47 PM ----------

These days, the trend is to use threads in one process.

There are ways to up the fd limit of a process, including the obvious one of forking off a child to close the listen/accept fd and finish all open I/O and let the parent close all the service fd and go back to accepting. This way, you get good response on short requests but long ones, if there are too many, are spun off once they get to the long part.
This User Gave Thanks to DGPickett For This Post:
# 4  
Old 10-20-2010
FWIW - consider reading 'Advanced Programming in the UNIX Environment' by Stevens & Rago.

It covers how to pass socket descriptors among processes. DGP mentioned one basic way.
There are others that do not involve threads, only sockets.

This kind of thing is way beyond what we can post here in the forums.
This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with data reformat if share share content

Input data: read1_data1 read1_data1 read2_data1 read3_data1 read4_data1 read4_data1 read4_data1 read5_data1 . . Desired output result: read1_data1 read1_data2 read2_data1 read3_data1 read4_data1 (3 Replies)
Discussion started by: perl_beginner
3 Replies

2. Programming

How Can I share a socket between childs?

Hello guys! I had seen some posts at this forum talking about my problem, but maybe my scenario is a little different, and I want other solutions. I saw users of this forums saying that the way to shared sockets is using UNIX Sockets, but this is the only way in my scenario? My Scenario:... (4 Replies)
Discussion started by: serpens11
4 Replies

3. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

4. Linux

To share socket fd between two process

Hello every one i am implementing client server program.To handle multiple fds of client in server i used poll function.But this poll not able to access socket fd from other process.How can i share socket fd between two process. Please Help me,Thanks in advance. (1 Reply)
Discussion started by: andrew.paul
1 Replies

5. Programming

Error with socket operation on non-socket

Dear Experts, i am compiling my code in suse 4.1 which is compiling fine, but at runtime it is showing me for socket programming error no 88 as i searched in errno.h it is telling me socket operation on non socket, what is the meaning of this , how to deal with this error , please... (1 Reply)
Discussion started by: vin_pll
1 Replies

6. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

7. Programming

which socket should socket option on be set

Hi all, On the server side, one socket is used for listening, the others are used for communicating with the client. My question is: if i want to set option for socket, which socket should be set on? If either can be set, what's the different? Again, what's the different if set option... (1 Reply)
Discussion started by: blademan100
1 Replies

8. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

9. Solaris

Identifying and grouping OS processes and APP processes

Hi Is there an easy way to identify and group currently running processes into OS processes and APP processes. Not all applications are installed as packages. Any free tools or scripts to do this? Many thanks. (2 Replies)
Discussion started by: wilsonee
2 Replies

10. UNIX for Advanced & Expert Users

Monitoring Processes - Killing hung processes

Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go? Thank you Richard (4 Replies)
Discussion started by: ukndoit
4 Replies
Login or Register to Ask a Question