Odd ouput redirection in background script
Ian Flanigan
flan at cics.Berkeley.EDU
Tue Feb 5 08:13:15 AEST 1991
Today I was cooking up a small program to save me the trouble of having to
wait for my rsh's to finish:
/* Background Processes */
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
if (fork())
exit(0);
execvp(argv[0],&argv[1]);
printf("OOps\n");
}
I used the following script to give it a test:
#!/bin/csh
ls > /tmp/tt$$
Then I typed, "background test_scr" to give it a test and it worked fine;
I got the output in the file in /tmp and everything. I then tried to use
it with rsh and it was a complete failure. Right away I remebered that
the child process inherits everything, so I needed to close stdin and
stdout. So the program became:
/* Background Processes */
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
if (fork())
exit(0);
close(0);
close(1);
execvp(argv[0],&argv[1]);
printf("OOps\n");
}
Easy. Now I gave it a test with, "background test_scr" and it wrote the
directory listing to my screen. My question: Why? Not only did I close
stdout, but I also had it re-directed in the script. Is it a probelem
with the shell?
I've gotten the program to work the way I want it to, now, but I am
baffled by the odd behavior.
Thanks for any info.
--
Ian Flanigan
flan at cics.wustl.edu "You can never have too many napkins."
wucs1.wustl.edu!cics!flan at uucp
More information about the Comp.unix.questions
mailing list