Csh & foreach causing fork problems

Neil Rickert rickert at mp.cs.niu.edu
Mon Mar 25 07:14:58 AEST 1991


In article <1991Mar24.201730.14808 at aucs.AcadiaU.ca> 880274d at aucs.acadiau.ca (Ralph Doncaster) writes:
>I'm having problems with a script I made to mail all the students on our
>system.   I often get a "fork: no more processes" error.
>I assume this is because foreach starts a new process for each argument it is
>given.
>
>#!/bin/csh
>if ($#argv) then
>	foreach i(`/bin/ls /u/student`)
>		mail -s $1 $i < $2
>		sleep 1
>	end

 Your problem is not really that 'foreach' is starting up a new process.
It is that 'mail' (which I presume is /usr/ucb/mail) is starting a new
process to put the delivery into the background.

 The real question is:

	Why on earth are you doing this?

 Why not send a single message to multiple recipients?  For example,
	mail -s $1 `/bin/ls /u/student` < $2
or even build the mail with the subject header (and perhaps a
'To: all-students:;' header)  in a file, and submit it to
/bin/mail with the list of recipients, or add a Bcc: header and submit
the message directly to sendmail with the -t operand.  Either way, only one
message is sent to multiple users, which should be considerably more efficient
and will certainly require less processes.

-- 
=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=
  Neil W. Rickert, Computer Science               <rickert at cs.niu.edu>
  Northern Illinois Univ.
  DeKalb, IL 60115                                   +1-815-753-6940



More information about the Comp.unix.questions mailing list