[net.unix-wizards] Repeat of a question posted to net.unix

pfeiffer@rsch.WISC.EDU (Phil Pfeiffer) (09/17/86)

Thought I'd post this request for info on how background shell jobs,
programs, and stdin/stdout interact on net.unix-wizards, because of the
lack of response from readers of net.unix.


The systems in question are 4.3BSD Unix and Ultrix.
The problem is as follows:


Assume that file "nxf" does not exist.
Assume that the following lines are in shell script 'cmd':
 
  #!/bin/csh
  rm nxf         >& cmd_out
  echo $status   >  cmd_stat


Assume the following lines are in shell script 'master': 

   #!( doesn't matter whether the csi is "/bin/sh" or "/bin/csh" )
   cmd

'master' executes just fine.  The "cannot find file" error message and
error status values are written into cmd_out and cmd_stat, respectively.
(the "cmd_stat" file contains a "1").


However, assume the following lines are in shell script 'bgmaster': 

   #!( doesn't matter whether the csi is "/bin/sh" or "/bin/csh" )
   cmd &
   wait

Now, if 'bgmaster' is executed, "cmd_out" is empty on return, and
"cmd_stat" contains the single line, "0".   Why?

Have I failed to understand something obvious about shell background processing?


-- 
-- Phil Pfeiffer

...!{harvard,ihnp4,seismo,topaz}!uwvax!pfeiffer
(608) 263-7308

dpz@topaz.RUTGERS.EDU (David P. Zimmerman) (09/20/86)

> Assume that file "nxf" does not exist.
> Assume that the following lines are in shell script 'cmd':
>  
>   #!/bin/csh
>   rm nxf         >& cmd_out
>   echo $status   >  cmd_stat

Same problem here on a 4.2 system.  But replace "rm nxf" with "ping
foo" or "test" and everything works OK.  Bug in rm?

				David
-- 
David P. Zimmerman		"Unix RULES!!!" - anonymous

Arpa: dpz@topaz.rutgers.edu
Uucp: ...{allegra | harvard | seismo | sri-iu | ut-sally}!topaz!dpz

avolio@decuac.DEC.COM (Frederick M. Avolio) (09/20/86)

> > Assume that file "nxf" does not exist.
> > Assume that the following lines are in shell script 'cmd':
> >   #!/bin/csh
> >   rm nxf         >& cmd_out
> >   echo $status   >  cmd_stat

> Same problem here on a 4.2 system.  But replace "rm nxf" with "ping
> foo" or "test" and everything works OK.  Bug in rm?

No a feature!  I answered the original poster by mail a week or two
ago (whenever it was posted).  After that the poster reposted to
net.unix-wizards saying there was no response from net.unix.
Suggestion -- wait a week or more for your article or propagate
through the net and another week to get something back before you
repost.

Rm checks to see if there is a controlling tty.  In the case of a
shell execing a background process, the child does not inherit the
controlling terminal.  Rm checks to see and if no controlling terminal
it acts as if you said "-f".  This is why no error message in this
case.
-- 
Fred @ DEC Ultrix Applications Center
INET: avolio@decuac.dec.com				* Fight the Fight *
UUCP: {decvax,seismo,cbosgd}!decuac!avolio	       * Rescue the Unborn *

mouse@mcgill-vision.UUCP (09/29/86)

In article <5867@topaz.RUTGERS.EDU>, dpz@topaz.RUTGERS.EDU (David P. Zimmerman) writes:
>> Assume that file "nxf" does not exist.
>> Assume that the following lines are in shell script 'cmd':
>>
>>   #!/bin/csh
>>   rm nxf         >& cmd_out
>>   echo $status   >  cmd_stat
>
> Same problem here on a 4.2 system.  But replace "rm nxf" with "ping
> foo" or "test" and everything works OK.  Bug in rm?

No, a feature in rm.  If rm's standard input is not a terminal, the -f
flag is turned on, which makes rm ignore all error conditions
(including "file does not exist").  I just now checked this in the 4.3
source code; presumably other systems which exhibit this behavior have
similar tests.

This is only sort of documented in the man page for rm; perhaps the
documentation should be cleaned up?

					der Mouse

USA: {ihnp4,decvax,akgua,utzoo,etc}!utcsri!mcgill-vision!mouse
     think!mosart!mcgill-vision!mouse
Europe: mcvax!decvax!utcsri!mcgill-vision!mouse
ARPAnet: think!mosart!mcgill-vision!mouse@harvard.harvard.edu

	Aren't you glad you don't shave with Occam's Razor?