From: SourceForge.net <no...@so...> - 2005-09-29 04:02:37
|
Bugs item #1306694, was opened at 2005-09-28 15:02 Message generated for change (Comment added) made by rbalakri You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=1306694&group_id=10894 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: 24. Channel Commands Group: current: 8.4.11 >Status: Open Resolution: None Priority: 5 Submitted By: Ravi Shankar. B (rbalakri) Assigned to: Andreas Kupries (andreas_kupries) Summary: Sockets are not working in the child processes Initial Comment: When a process is forked and if socket is executed within the child process the socket is not accepting the incoming connection. Tcl version: 8.4.11 Platform: Linux Tcl Version is compiled with threading enabled. The following is the sample server (daytime server) program to reproduce the problem, proc Server {channel clientaddr clientport} { puts "Connection from $clientaddr registered" puts $channel [clock format [clock seconds]] sleep 30 close $channel } if { [fork] } { # Parent wait exit } else { # child socket -server Server 9900 puts "child waiting for sockets" vwait forever } The corresponding client program, set server localhost set sockChan [socket $server 9900] gets $sockChan line close $sockChan puts "The time on $server is $line" After the server is started and after starting the client netstat comman gives the following output, [root@myhost test]# netstat -atp | grep 9900 tcp 0 0 *:9900 *:* LISTEN 4309/tcl tcp 0 0 myhost:36222 myhost:9900 ESTABLISHED 4291/tcl tcp 0 0 myhost:9900 myhost:36222 ESTABLISHED - The first one is the server's listening socket, second is clients socket and third is server's connected socket. As you can see the sever's socket doesn't have the application associated with it. ---------------------------------------------------------------------- >Comment By: Ravi Shankar. B (rbalakri) Date: 2005-09-29 09:32 Message: Logged In: YES user_id=431412 I've threaded server (for each client connection a worker thread will be created to handle the client request) and I want to daemoize the server. For that I'm using the following piece of procedure. Can you suggest some alternatives if what I'm doing is not correct ? daemonize signal ignore SIGHUP signal unblock {SIGQUIT SIGTERM} signal trap {SIGQUIT SIGTERM} [subst {shutdown $arg(immediate)}] my_server <server args> proc daemonize {} { global data if {[fork]} { exit 0 } id process group set signal ignore SIGHUP if {[fork]} { # child doesn't get exited and gets into a mutex # deadlock when --enable-threads is enabled while TCL compilation # see bug ids 923072 and 749639 in sourceforge.net kill SIGKILL [pid] exit 0 } close stdin close stdout close stderr set fd [open /dev/null r] set fd [open /dev/null w] set fd [open /dev/null w] cd / umask 022 return [id process] } proc shutdown { immediate } { # Check if all the worker threads are shutdown # and then exit the process } ---------------------------------------------------------------------- Comment By: Jeffrey Hobbs (hobbs) Date: 2005-09-28 23:27 Message: Logged In: YES user_id=72656 Fork and threads are not a valid combination. If you have a threaded build, please use another thread, not fork. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=110894&aid=1306694&group_id=10894 |