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 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho