Bug 10779 - can't background a process with tcl; this used to work!
Summary: can't background a process with tcl; this used to work!
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Red Hat Raw Hide
Classification: Retired
Component: tcltk
Version: 1.0
Hardware: All
OS: Linux
medium
high
Target Milestone: ---
Assignee: Jens Petersen
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2000-04-13 06:19 UTC by Jonathan Kamens
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2000-05-23 09:12:17 UTC
Embargoed:


Attachments (Terms of Use)

Description Jonathan Kamens 2000-04-13 06:19:42 UTC
Create this script called "foo.pl":

--cut here--
#!/usr/bin/perl

if (! ($pid = fork)) {
    close(STDIN);
    close(STDOUT);
    close(STDERR);
    sleep(5);
    exit(0);
}
else {
    exit(0);
}
--cut here--

Now create this tcl script, called "foo.tcl":

--cut here--
exec foo.pl
exit
--cut here--

Now run "tclsh foo.tcl".  It will exit after five seconds.  It *should*
exit immediately, and indeed, it does exit immediately in tcl-8.0.5-34.

I've managed to figure out that the child process started by tcl's
"exec" call is inheriting some file descriptors which should have been
set to close on exec by tcl but weren't.  When "exit" is called in the
tcl script, tcl waits until those file descriptors are closed before it
actually exits.  This is obnoxious, undocumented, just plain wrong
behavior.

You can confirm this by creating this file foo.c:

--cut here--
#include <stdio.h>

main()
{
  int i;

  if (fork()) {
    exit(0);
  }

  for (i = 0; i < 64; i++) {
    close(i);
  }
  sleep(5);
  exit(0);
}
--cut here--

Compile this with "gcc -o foo foo.c", then change foo.tcl so that it
calls "exec ./foo" instead of "exec ./foo.pl", then run "tcl foo.tcl"
and it'll exit immediately.  If you take out the "close(i);" and
recompile foo.c to foo, foo.tcl will once again take five seconds to
exit.

This is a serious problem which makes it virtually impossible to
construct tcl or expect scripts which launch daemons or do other
common things which intentionally leave processes sitting around after
the script exits.

Comment 1 Jeff Johnson 2000-04-13 09:02:59 UTC
What version of tcltk?

Comment 2 Jonathan Kamens 2000-04-13 12:35:59 UTC
tcltk-8.2.3-36 doesn't work.  tcltk-8.0.5-34 works.  Sorry I forgot to mention
this.

Comment 3 Jonathan Kamens 2000-05-23 09:12:59 UTC
This is fixed in tcl 8.3.1.

Comment 4 Jeff Johnson 2000-06-03 14:04:16 UTC
Fixed (by upgrading to tcl-8.3.1) in Raw Hide. Thanks for reporting the problem
(and fix).


Note You need to log in before you can comment on or make changes to this bug.