LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices

Reply
 
Search this Thread
Old 07-13-2005, 05:46 AM   #1
MScheffer
LQ Newbie
 
Registered: Jul 2005
Posts: 2

Rep: Reputation: 0
shutdown(2) after fork(2) behaviour changed or undefined?


Hi,

Is there a definition of how a Socket shutdown(2) operation should behave if there is still a child process that has the socket open as well?
Although not that pretty, code like the one below has been working as intended for years (AIX3, 4, Suse7). Under Fedora Core 3 (2.6.11-1.27 kernel), however, I noticed that the client process does no longer receive requests.

Any help is appreciated,

Mark.

Code:
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>

main()
{
        int sok = do_listen (12345);
        if (fork())
                shutdown (sok, SHUT_RD);
        else
                sleep (120);  // Try connecting with e.g. telnet localhost 12345
}

int do_listen (int port)
{
        int     sok;
        struct  sockaddr_in     s;

        sok = socket (AF_INET, SOCK_STREAM, 0);

        s.sin_family = AF_INET;
        s.sin_port = htons (port);
        s.sin_addr.s_addr = INADDR_ANY;

        bind (sok, (struct sockaddr *)&s, sizeof(s));
        listen (sok, 5);

        return sok;
}
 
Old 07-14-2005, 04:44 PM   #2
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 117Reputation: 117
My guess would be that (since it is only a single socket) that SHOULD actually shut it down. I guess one would have to look at the POSIX spec to see how it's intended to work.

Is there a reason your code needs to do that? (Obviously the code above is just a sample)
 
Old 07-15-2005, 01:20 AM   #3
MScheffer
LQ Newbie
 
Registered: Jul 2005
Posts: 2

Original Poster
Rep: Reputation: 0
Quote:
My guess would be that (since it is only a single socket) that SHOULD actually shut it down. I guess one would have to look at the POSIX spec to see how it's intended to work.
http://www.opengroup.org/onlinepubs/...html#tag_02_10 does not even mention the shutdown() operation. The only information on shutdown is available through http://www.opengroup.org/onlinepubs/...shutdown.html.

Quote:
Is there a reason your code needs to do that? (Obviously the code above is just a sample)
I can't find a reason. Either you manage the socket from the parent only or from the child process. The problem is that in the actual case the problem was hidden in libraries with an atexit() to clean up the sockets.... Took some effort to see what was going on (a fork() does not simplify debugging)
Fixing the problem took only a few seconds.
 
Old 07-15-2005, 09:11 AM   #4
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 117Reputation: 117
Well, I'm glad that you were able to fix it. I'm sorry if my post added to the confusion rather than helped to clear it up.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help on how to save services shutdown or shutdown from the terminal. wambuzz Linux - General 2 03-11-2005 07:38 AM
Linux full shutdown vs. manual shutdown? LQtoto Linux - General 9 01-26-2005 06:21 PM
Wierd behaviour using fork() and pipe() cybermix Programming 4 01-08-2004 03:44 AM
konsole shutdown possible? or key combo = shutdown possible? Laptop2250 Linux - Newbie 3 11-16-2003 10:44 AM
Strange behaviour of fork call in Linux Uzair Programming 1 02-12-2003 01:37 PM


All times are GMT -5. The time now is 02:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration