All Forums |
Register |
Login |
Search |
Subscriptions |
My Profile |
Inbox |
Tool Warehouse |
FAQs |
Resources |
Help |
Member List |
Address Book |
Logout |
|
|
background processes launched by perl "system" command behave strangely in ksh -l or ksh -lc
|
Logged in as: Guest |
Users viewing this topic: none |
|
Login |
|
|
background processes launched by perl "system"... - Feb. 7, '06, 6:03:55 AM
|
|
|
gutnor
Posts: 2
Joined: Dec. 25, '05,
Status: offline
|
For an application we are currently porting we ran into a case where a perl script launched from Windows needs to create a background process that outputs logging in a file.
If launched from within an Interix interactive terminal, everything runs ok, but using posix.exe on command line it is not.
Here is a little test scenario:
I create 2 scripts (I used /tmp folder here but I had the same problem in other folder) :
cat > /tmp/test.pl <<!
#! /usr/local/bin/perl
use Socket;
use POSIX;
system("/tmp/test.sh &");
!
cat > /tmp/test.sh <<!
#! /bin/sh
/bin/echo Hello1 > /tmp/hello1.txt
/bin/echo Hello2 > /tmp/hello2.txt
!
TEST1:
From Windows command prompt launch ksh:
> posix.exe /u /c ksh -l
and from ksh launch test.pl:
% /tmp/test.pl
/tmp/hello1.txt is created and contains "Hello1" as expected.
/tmp/hello2.txt is also created and contains "Hello2" as expected.
TEST2:
From Windows command prompt launch the script (NB: same as using ksh.bat provided with Interix):
> posix.exe /u /c ksh -lc /tmp/test.pl
/tmp/hello1.txt is created but contains nothing !
/tmp/hello2.txt is NOT created.
( NB: Same problem when using
posix.exe /u /c ksh -c /tmp/test.pl
posix.exe /u /c /usr/local/bin/perl /tmp/test.pl
posix.exe /u /c /tmp/test.pl
replacing system("/tmp/test.sh &"); by system("/bin/ksh -lc /tmp/test.sh &");
)
Fixing the test scenario is easy, we already found several workarounds,
like
a. Not calling the task in background from perl - system("/tmp/test.sh &");
b. Using `/tmp/test.sh &` instead of system("/tmp/test.sh &")
but I may not be possible to fix everything as easily in the real scripts and could require significant testing on other Unix platform ...
Worse, we do not understand what's happening and therefore we think we may have only hit the tip of the iceberg ...
Does somebody understand the problem here ? Is there a problem with perl forking or are we hitting a hidden limit somewhere ?
Thanks,
Vincent
PS:
Our 2 test systems are
Win2000 Professional SP4
SFU 3.5
P4 1.8 GHz with 1GB memory
P4 2.4 GHz with 2GB memory
|
|
|
RE: background processes launched by perl "system&... - Feb. 10, '06, 12:30:44 AM
|
|
|
markfunk
Posts: 670
Joined: Mar. 31, '03,
Status: offline
|
Try setting stdout and stderr to valid Interix file descriptors
rather than relying on the Windows ones.
So, use :
posix.exe -u -c /bin/ksh -l -c "/tmp/test10.pl > /dev/null 2>&1"
|
|
|
RE: background processes launched by perl "system&... - Feb. 10, '06, 7:39:51 PM
|
|
|
gutnor
Posts: 2
Joined: Dec. 25, '05,
Status: offline
|
Thanks a lot ! That fixed our problem.
BTW, during our testing we noticed this strange behavior only with Win2K family.
Thanks,
Vincent
|
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
|
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts |
|
|
|