Bug 10779 - can't background a process with tcl; this used to work!
can't background a process with tcl; this used to work!
Status: CLOSED RAWHIDE
Product: Red Hat Raw Hide
Classification: Retired
Component: tcltk (Show other bugs)
1.0
All Linux
medium Severity high
: ---
: ---
Assigned To: Jens Petersen
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2000-04-13 02:19 EDT by Jonathan Kamens
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2000-05-23 05:12:17 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description Jonathan Kamens 2000-04-13 02:19:42 EDT
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 05:02:59 EDT
What version of tcltk?
Comment 2 Jonathan Kamens 2000-04-13 08:35:59 EDT
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 05:12:59 EDT
This is fixed in tcl 8.3.1.
Comment 4 Jeff Johnson 2000-06-03 10:04:16 EDT
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.