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
For 2021 - online Python 3 training - see ((here)).

Our plans were to retire in summer 2020 and see the world, but Coronavirus has lead us into a lot of lockdown programming in Python 3 and PHP 7.
We can now offer tailored online training - small groups, real tutors - works really well for groups of 4 to 14 delegates. Anywhere in the world; course language English.

Please ask about private 'maintenance' training for Python 2, Tcl, Perl, PHP, Lua, etc.
There are some defunct processes after close socke

Posted by rdczhju (rdczhju), 25 August 2004

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
} 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 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., 2022: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho