Forking with Tclsh vs Wish

Hello,

I am new to this site, so sorry ahead of time if this is not the right place for this question.......anywhooooo

I am having troubles with forking new processes in wish. Take the following code example:

****************************
package require Tclx
puts "TCL VER: [info tclversion]"

proc spawnChildren {} {
for {set i_vii 0} {$i_vii < 5} {incr i_vii} {
set temp_vii [fork]
if {$temp_vii == 0} {

# Child Process

puts "child pid is: [pid]"

exit 1

} else {

# Parent Process

puts "parent\[[pid]\]: sees the child pid as $temp_vii"

# Store off child pids to collect later

lappend finalPid_vil $temp_vii

}
}
foreach pid_vii $finalPid_vil {
# Collect all zombie child process
wait $pid_vii
}
puts "parent out of loop: $finalPid_vil"
}
# Spawn 5 children off
spawnChildren
puts "out of spawning"
***************************

If I run this TCL script with tclsh I get the following output:

Monday|May.05|03:25PM> tclsh temp.tcl
TCL VER: 8.4
child pid is: 10469
parent[10468]: sees the child pid as 10469
child pid is: 10470
parent[10468]: sees the child pid as 10470
child pid is: 10471
parent[10468]: sees the child pid as 10471
parent[10468]: sees the child pid as 10472
child pid is: 10473
parent[10468]: sees the child pid as 10473
child pid is: 10472
parent out of loop: 10469 10470 10471 10472 10473
out of spawning

PERFECT...Just like I expect

But now I run it with Wish:
Monday|May.05|03:27PM> wish temp.tcl
TCL VER: 8.4
child pid is: 10481
parent[10480]: sees the child pid as 10481
child pid is: 10482
X connection to :0.0 broken (explicit kill or server shutdown).
parent[10480]: sees the child pid as 10482
child pid is: 10483
X connection to :0.0 broken (explicit kill or server shutdown).
parent[10480]: sees the child pid as 10483
child pid is: 10484
X connection to :0.0 broken (explicit kill or server shutdown).
parent[10480]: sees the child pid as 10484
child pid is: 10485
parent[10480]: sees the child pid as 10485
X connection to :0.0 broken (explicit kill or server shutdown).
parent out of loop: 10481 10482 10483 10484 10485
out of spawning
X connection to :0.0 broken (explicit kill or server shutdown).

Why am I receiving these X Errors? Is wish overriding the normal exit procedure and then causing havoc?

I am running redhat 4.0 Enterprise with Tcl 8.4. Any help would be greatly appreciated. Thanks ahead of time!!! :confused:

I also just learned if I do the following then the errors go away:

package require Tclx

proc spawnChildren {} {
for {set i_vii 0} {$i_vii < 5} {incr i_vii} {
set temp_vii [fork]
if {$temp_vii == 0} {

[INDENT]# Child Process
puts "child pid is: [pid]"
exec kill -9 [pid]
} else {
# Parent Process
puts "parent\[[pid]\]: sees the child pid as $temp_vii"
# Store off child pids to collect later
lappend finalPid_vil $temp_vii
}
}
foreach pid_vii $finalPid_vil {
# DO NOT Collect all the zombie child process
}
puts "parent out of loop: $finalPid_vil"[/INDENT]
}

# Spawn 5 children off
spawnChildren
puts "out of spawning"

So now by calling the linux system kill command and not waiting for any of the Zombie Processes the script works just fine. Now the only problem is that a bunch of defunct/zombie processes are now taking up space in the process table (which is not a problem unless the system runs out of entries). So any ideas of why this might be happening as I can recreate the same issue with perl/tk as well :frowning:

Wish is the graphical toolkit 'shell' of TCL/TK. Obviously it tries to connect to the X server on your platform. If you don't want the errors output catch the kill and wait commands.

TclX and wish or expect and wish are not guaranteed to work well together.
See here: TclX

Ok...well I can get the same X Errors without even using wish. If I take the same example in my first post but also do a "package require Tk" then source that file with tclsh, I will receive the same X Errors. So it has nothing to do with wish (I just realized this today). It has to do something with sourcing the Tk library. This was evident to me when I was able to recreate the same problem with Perl/Tk. Is there anyway to gracefully close the X Server connection in Tk?