Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!mp.cs.niu.edu!rickert From: rickert@mp.cs.niu.edu (Neil Rickert) Newsgroups: comp.unix.questions Subject: Re: Csh & foreach causing fork problems Message-ID: <1991Mar24.211458.6525@mp.cs.niu.edu> Date: 24 Mar 91 21:14:58 GMT References: <1991Mar24.201730.14808@aucs.AcadiaU.ca> Organization: Northern Illinois University Lines: 35 In article <1991Mar24.201730.14808@aucs.AcadiaU.ca> 880274d@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 Northern Illinois Univ. DeKalb, IL 60115 +1-815-753-6940