You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@tcl.apache.org by Paul Buhr <pb...@vision-systems.de> on 2002/06/27 17:49:56 UTC

problems with child processes

Hello,

I wrote a tcl-Skript, what runs command-line processes to get
informations which are used. Sometime it works, sometimes it crashes.
When it crashes, I get the following error:

 5:44pm  up 2 days,  9:28,  0 users,  load average: 0.05, 0.06, 0.08
error waiting for process to exit: child process lost (is SIGCHLD
ignored or trapped?)
    while executing
"exec uptime"


followed by the code of the script. When I run the script using tclsh, I
never receive an error message like this... what do I wrong?


Here the source....



 # Last auslesen
set uptime [exec uptime]
set last [string trim [string range $uptime [expr [string last ","
$uptime] + 1] end]]

# Hostnamen auslesen
set thishost [exec hostname]

# Arbeitsspeicher
set mem [exec free | grep "Mem"]
set memtemp  [string trim [string range $mem [expr [string first " "
$mem] + 1] end]]
set totalmem  [string trim [string range $memtemp 0 [expr [string first
" " $memtemp] + 1]]]
set memtemp  [string trim [string range $memtemp [expr [string first " "
$memtemp] + 1] end]]
set usedmem [string trim [string range $memtemp 0 [expr [string first "
" $memtemp] + 1]]]
set memtemp  [string trim [string range $memtemp [expr [string first " "
$memtemp] + 1] end]]
set freemem [string trim [string range $memtemp 0 [expr [string first "
" $memtemp] + 1]]]

# Swap-Speicher
set swap [exec free | grep "Swap"]
set swaptemp  [string trim [string range $swap [expr [string first " "
$swap] + 1] end]]
set totalswap  [string trim [string range $swaptemp 0 [expr [string
first " " $swaptemp] + 1]]]
set swaptemp  [string trim [string range $swaptemp [expr [string first "
" $swaptemp] + 1] end]]
set usedswap [string trim [string range $swaptemp 0 [expr [string first
" " $swaptemp] + 1]]]
set freeswap  [string trim [string range $swaptemp [expr [string first "
" $swaptemp] + 1] end]]

# Prozessorinformation
set procinfo [exec cat /proc/cpuinfo]


### AUSGABE ###
puts "<HTML><HEAD>"
puts "<TITLE>System-Monitor</TITLE>"
puts "<META HTTP-EQUIX=\"REFRESH\" CONTENT=\"60\">"
puts "</HEAD><BODY BGCOLOR=\"#1929FF\" TEXT=\"#FFFF00\" FACE=\"COURIER\">"
puts "<B><U>Hostname:</U></B> $thishost<BR>"
puts "<B><U>durchschnittliche CPU-Last:</U></B> $last<BR>"
puts "<BR><BR><BR>"
puts "<FONT COLOR=\"#FFFFFF\"><H2>Speicherauslastung</H2></FONT>"
puts "<TABLE BORDER=\"2\" BORDERCOLOR=\"#1111EE\" BGCOLOR=\"#800000\">"
puts "<TR>"
puts "<TD BGCOLOR=\"#008000\"><B><I>Speichertyp</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>gesamt</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>belegt</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>frei</I></B></TD>"
puts "</TR>"
puts "<TR>"
puts "<TD BGCOLOR=\"#000080\"><FONT
COLOR=\"#FFFFFF\">psysikalisch</FONT></TD>"
puts "<TD>$totalmem</TD>"
puts "<TD>$usedmem</TD>"
puts "<TD>$freemem</TD>"
puts "</TR>"
puts "<TR>"
puts "<TD BGCOLOR=\"#000080\"><FONT
COLOR=\"#FFFFFF\">Auslagerung</FONT></TD>"
puts "<TD>$totalswap</TD>"
puts "<TD>$usedswap</TD>"
puts "<TD>$freeswap</TD>"
puts "</TR>"
puts "</TABLE>"
puts "<BR><BR><BR>"
puts "<FONT COLOR=\"#FFFFFF\"><H2>Prozessorinformation</H2></FONT>"
puts "<TABLE BORDER=\"0\" BGCOLOR=\"#FFFF00\"><TR><TD><FONT
COLOR=\"#000000\"><PRE>$procinfo</PRE></FONT></TD></TR></TABLE>"
puts "<BR><BR><BR>"
puts "<FONT COLOR=\"#FFFFFF\"><H2>Massenspeicher</H2></FONT>"


# Massenspeicher
puts "<TABLE BORDER=\"2\" BORDERCOLOR=\"#1111EE\" BGCOLOR=\"#800000\">"
puts "<TR>"
puts "<TD BGCOLOR=\"#008000\"><B><I>Device</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>Gr&ouml;&szlig;e</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>belegt</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>frei</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>in %</I></B></TD>"
puts "<TD BGCOLOR=\"#008000\"><B><I>Mountpoint</I></B></TD>"
puts "</TR>"

set mass [exec df | grep "dev"]
foreach drive [split $mass "\n"] {
set drivename [string trim [string range $drive 0 [expr [string first "
" $drive] + 1]]]
set drivetemp [string trim [string range $drive [expr [string first " "
$drive] + 1] end]]
set drivetotal [string trim [string range $drivetemp 0 [expr [string
first " " $drivetemp] + 1]]]
set drivetemp [string trim [string range $drivetemp [expr [string first
" " $drivetemp] + 1] end]]
set driveused [string trim [string range $drivetemp 0 [expr [string
first " " $drivetemp] + 1]]]
set drivetemp [string trim [string range $drivetemp [expr [string first
" " $drivetemp] + 1] end]]
set drivefree [string trim [string range $drivetemp 0 [expr [string
first " " $drivetemp] + 1]]]
set drivetemp [string trim [string range $drivetemp [expr [string first
" " $drivetemp] + 1] end]]
set drivefull [string trim [string range $drivetemp 0 [expr [string
first " " $drivetemp]]]]
set drivemount [string trim [string range $drivetemp [expr [string first
" " $drivetemp] + 1] end]]

puts "<TR>"
puts "<TD><I>$drivename</I></TD>"
puts "<TD>$drivetotal</TD>"
puts "<TD>$driveused</TD>"
puts "<TD>$drivefree</TD>"
puts "<TD><B>$drivefull</B></TD>"
puts "<TD><I>$drivemount</I></TD>"
puts "</TR>"

}
puts "</TABLE>"
puts "</BODY></HTML>"

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@tcl.apache.org
For additional commands, e-mail: general-help@tcl.apache.org


Re: problems with child processes

Posted by "David N. Welton" <da...@dedasys.com>.
"Paul Buhr" <pb...@vision-systems.de> writes:

Hi - I'm not sure which Apache Tcl product you are using...  I'll
assume mod_dtcl, though.  You should follow up to that list.

> I wrote a tcl-Skript, what runs command-line processes to get
> informations which are used. Sometime it works, sometimes it
> crashes.  When it crashes, I get the following error:
 
>  5:44pm  up 2 days,  9:28,  0 users,  load average: 0.05, 0.06, 0.08
> error waiting for process to exit: child process lost (is SIGCHLD
> ignored or trapped?)
>     while executing
> "exec uptime"

> followed by the code of the script. When I run the script using
> tclsh, I never receive an error message like this... what do I
> wrong?

I bet it's one of these other exec's...
 
Try putting each one on its own page, and seeing if they work.  This
will help you figure out which one is broken, or having trouble.

Another way to make sure that the page at least doesn't break is to
make use of the 'catch' command.

> set mem [exec free | grep "Mem"]

If I were you, I might consider making a Tcl interface to libproc, and
then just call that from Tcl.  It would be more efficient.

This is probably better done in a style like this:

set HTML {

<lots of html> ....

%s ... %d %d

}

puts [format $HTML $variableone $hostname $mem $blah $blah $blah]

Or just use the template facilities of mod_dtcl:

<html>
<blah>
<blah>
<blah>
<? puts $hostname ?>
<blah>
<blah>
<blah>

Either one of those is more efficient than a huge amount of puts
statements:

> puts "<HTML><HEAD>"
> puts "<TITLE>System-Monitor</TITLE>"
> puts "<META HTTP-EQUIX=\"REFRESH\" CONTENT=\"60\">"
> puts "</HEAD><BODY BGCOLOR=\"#1929FF\" TEXT=\"#FFFF00\" FACE=\"COURIER\">"
> puts "<B><U>Hostname:</U></B> $thishost<BR>"
> puts "<B><U>durchschnittliche CPU-Last:</U></B> $last<BR>"
> puts "<BR><BR><BR>"
> puts "<FONT COLOR=\"#FFFFFF\"><H2>Speicherauslastung</H2></FONT>"
> puts "<TABLE BORDER=\"2\" BORDERCOLOR=\"#1111EE\" BGCOLOR=\"#800000\">"
> puts "<TR>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>Speichertyp</I></B></TD>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>gesamt</I></B></TD>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>belegt</I></B></TD>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>frei</I></B></TD>"
> puts "</TR>"
> puts "<TR>"
> puts "<TD BGCOLOR=\"#000080\"><FONT
> COLOR=\"#FFFFFF\">psysikalisch</FONT></TD>"
> puts "<TD>$totalmem</TD>"
> puts "<TD>$usedmem</TD>"
> puts "<TD>$freemem</TD>"
> puts "</TR>"
> puts "<TR>"
> puts "<TD BGCOLOR=\"#000080\"><FONT
> COLOR=\"#FFFFFF\">Auslagerung</FONT></TD>"
> puts "<TD>$totalswap</TD>"
> puts "<TD>$usedswap</TD>"
> puts "<TD>$freeswap</TD>"
> puts "</TR>"
> puts "</TABLE>"
> puts "<BR><BR><BR>"
> puts "<FONT COLOR=\"#FFFFFF\"><H2>Prozessorinformation</H2></FONT>"
> puts "<TABLE BORDER=\"0\" BGCOLOR=\"#FFFF00\"><TR><TD><FONT
> COLOR=\"#000000\"><PRE>$procinfo</PRE></FONT></TD></TR></TABLE>"
> puts "<BR><BR><BR>"
> puts "<FONT COLOR=\"#FFFFFF\"><H2>Massenspeicher</H2></FONT>"

Good luck, and let me know if it works,
-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: mod_dtcl-unsubscribe@tcl.apache.org
For additional commands, e-mail: mod_dtcl-help@tcl.apache.org


Re: problems with child processes

Posted by "David N. Welton" <da...@dedasys.com>.
"Paul Buhr" <pb...@vision-systems.de> writes:

Hi - I'm not sure which Apache Tcl product you are using...  I'll
assume mod_dtcl, though.  You should follow up to that list.

> I wrote a tcl-Skript, what runs command-line processes to get
> informations which are used. Sometime it works, sometimes it
> crashes.  When it crashes, I get the following error:
 
>  5:44pm  up 2 days,  9:28,  0 users,  load average: 0.05, 0.06, 0.08
> error waiting for process to exit: child process lost (is SIGCHLD
> ignored or trapped?)
>     while executing
> "exec uptime"

> followed by the code of the script. When I run the script using
> tclsh, I never receive an error message like this... what do I
> wrong?

I bet it's one of these other exec's...
 
Try putting each one on its own page, and seeing if they work.  This
will help you figure out which one is broken, or having trouble.

Another way to make sure that the page at least doesn't break is to
make use of the 'catch' command.

> set mem [exec free | grep "Mem"]

If I were you, I might consider making a Tcl interface to libproc, and
then just call that from Tcl.  It would be more efficient.

This is probably better done in a style like this:

set HTML {

<lots of html> ....

%s ... %d %d

}

puts [format $HTML $variableone $hostname $mem $blah $blah $blah]

Or just use the template facilities of mod_dtcl:

<html>
<blah>
<blah>
<blah>
<? puts $hostname ?>
<blah>
<blah>
<blah>

Either one of those is more efficient than a huge amount of puts
statements:

> puts "<HTML><HEAD>"
> puts "<TITLE>System-Monitor</TITLE>"
> puts "<META HTTP-EQUIX=\"REFRESH\" CONTENT=\"60\">"
> puts "</HEAD><BODY BGCOLOR=\"#1929FF\" TEXT=\"#FFFF00\" FACE=\"COURIER\">"
> puts "<B><U>Hostname:</U></B> $thishost<BR>"
> puts "<B><U>durchschnittliche CPU-Last:</U></B> $last<BR>"
> puts "<BR><BR><BR>"
> puts "<FONT COLOR=\"#FFFFFF\"><H2>Speicherauslastung</H2></FONT>"
> puts "<TABLE BORDER=\"2\" BORDERCOLOR=\"#1111EE\" BGCOLOR=\"#800000\">"
> puts "<TR>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>Speichertyp</I></B></TD>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>gesamt</I></B></TD>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>belegt</I></B></TD>"
> puts "<TD BGCOLOR=\"#008000\"><B><I>frei</I></B></TD>"
> puts "</TR>"
> puts "<TR>"
> puts "<TD BGCOLOR=\"#000080\"><FONT
> COLOR=\"#FFFFFF\">psysikalisch</FONT></TD>"
> puts "<TD>$totalmem</TD>"
> puts "<TD>$usedmem</TD>"
> puts "<TD>$freemem</TD>"
> puts "</TR>"
> puts "<TR>"
> puts "<TD BGCOLOR=\"#000080\"><FONT
> COLOR=\"#FFFFFF\">Auslagerung</FONT></TD>"
> puts "<TD>$totalswap</TD>"
> puts "<TD>$usedswap</TD>"
> puts "<TD>$freeswap</TD>"
> puts "</TR>"
> puts "</TABLE>"
> puts "<BR><BR><BR>"
> puts "<FONT COLOR=\"#FFFFFF\"><H2>Prozessorinformation</H2></FONT>"
> puts "<TABLE BORDER=\"0\" BGCOLOR=\"#FFFF00\"><TR><TD><FONT
> COLOR=\"#000000\"><PRE>$procinfo</PRE></FONT></TD></TR></TABLE>"
> puts "<BR><BR><BR>"
> puts "<FONT COLOR=\"#FFFFFF\"><H2>Massenspeicher</H2></FONT>"

Good luck, and let me know if it works,
-- 
David N. Welton
   Consulting: http://www.dedasys.com/
     Personal: http://www.dedasys.com/davidw/
Free Software: http://www.dedasys.com/freesoftware/
   Apache Tcl: http://tcl.apache.org/

---------------------------------------------------------------------
To unsubscribe, e-mail: general-unsubscribe@tcl.apache.org
For additional commands, e-mail: general-help@tcl.apache.org