Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
This week, we're updating our course layouts and descriptions. Presentation and materials always gently change over time, but just occasionally there's a need to make a step change to clear out some of the old and roll in the new. That's now happening - but over a long and complex site it's not instant and you'll see sections of the site changing up to and including 19th September.

See also [here] for status update
 
There are some defunct processes after close socke

Posted by rdczhju (rdczhju), 25 August 2004
Hi,

There are some defunct processes after I close sockets. I don't know why and how did this happen? would you please give me some comments on my script?

I paste my socket server script here:
#!/opt/sfw/bin/expect --

set PORT 7777

proc Listener { newSock addr port } {
       puts "New client $newSock from $addr port $port"
       fconfigure $newSock -buffering line
       fileevent $newSock readable [ list Handler $newSock ]
}

proc Handler {sock} {
global env

       if { [ eof $sock] || [catch {gets $sock line} ] } {
               close $sock
               puts "Close socket."
       } else {
               switch -regexp -- $line {
                       ^QUIT$ {
                               close $sock
                               puts "Close socket on demand."
                       }
                       {^\[DIST\]} {
                               set info [lindex [split $line =] 1]
                       set dist [lindex [split $info] 0]
                       set env(DIST_LIB_PATH) [lindex [split $info] 1]
                               if [ catch { exec $dist <@ $sock >@ $sock 2>@ stderr & } Catch ] {
                                       puts $sock "\[ERROR\]: $dist can't be started ($Catch)."
                               }
                       fileevent $sock readable ""
                       close $sock
                       }
                       default {
                               puts $sock "\[SERVER\]"
                       }
               }
       }
}

if { $argc == 0 } {
       while 1 {
                spawn -noecho $argv0 $PORT
                wait
       }
} else {
       set port [ lindex $argv 0 ]
       set s [ socket -server Listener [ format "%d" $port ] ]
       vwait forever
}

Is there some wrong with my script?

thanks in advance!

Posted by admin (Graham Ellis), 26 August 2004
Oh help!    It's a morning for excellent specialist questions here.  Not sure how much I can help .... but I CAN tell you that one of the usual reasons for defunct processes or zombies being left after a child process completes is that children always send a signal (SIGCHLD) to the parent when they exit and they hang around until the parent has received it.  Sounds like what's happening here?   I would be very tempted to get your Tcl to receive and ignore SIGCHLD signals and ignore them.   If youwant to search the net for examples, the action of receiveing and ignoring child terminations is often known as "reaping children".



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho