From owner-freebsd-questions Fri Dec 27 14:10:14 1996 Return-Path: Received: (from root@localhost) by freefall.freebsd.org (8.8.4/8.8.4) id OAA10878 for questions-outgoing; Fri, 27 Dec 1996 14:10:14 -0800 (PST) Received: from xmission.xmission.com (softweyr@xmission.xmission.com [198.60.22.2]) by freefall.freebsd.org (8.8.4/8.8.4) with ESMTP id OAA10872 for ; Fri, 27 Dec 1996 14:10:08 -0800 (PST) Received: (from softweyr@localhost) by xmission.xmission.com (8.8.4/8.7.5) id PAA21484; Fri, 27 Dec 1996 15:10:03 -0700 (MST) From: Softweyr LLC Message-Id: <199612272210.PAA21484@xmission.xmission.com> Subject: Re: multi-media app runs out of forking capabilities To: kline@tera.com (Gary Kline) Date: Fri, 27 Dec 1996 15:10:02 -0700 (MST) Cc: questions@freebsd.org In-Reply-To: <199612271912.LAA11283@athena.tera.com> from "Gary Kline" at Dec 27, 96 11:12:30 am X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-questions@freebsd.org X-Loop: FreeBSD.org Precedence: bulk Gary Kline asked: > Is there a way that one program can send a flag > to another program? Assuming yes, where is some > sample code?? According to Softweyr LLC: % Sure. Signals are a simple, but error prone way. A UNIX-domain socket % or a FIFO would work well, or even a MSGQ. You can find instructions % on using most (or maybe all) of these in W. Richard Stevens' excellent % books _UNIX Network Programming_ (0-13-949876-1) and _Advanced % Programming in the UNIX Environment_ (0-201-56317-7), both from % Prentice Hall. > I've already tried a FIFO; close, but no cigar. Looks like > spawning a new proc is the bbest way. I have an older version > of Stevens' networking text. Probably ought to check out the > _Advanced_ book. Do you know when it was published, off-hand? > Anyway, thanks for the pointers. You can find it currently at www.bookpool.com. The copyright date is 1990, but it is certainly still "current." If yo've already tried a FIFO and can't get your information from one process to another, none of the other options are going to help you; they are more generalized forms of communication. You should carefull consider what it is that the parent process really needs to tell the child process. % Your 'can't fork' messages may be caused by the per-process limits on % child processes. Are you gathering the status of your child processes % with wait(2) at any point? If not, all of your child processes will % remain counted against your per-process limit until you wait() for them. % Richards UNIX book will explain the UNIX process model and the relation- % ship between parent and child processes better than I can here. ;^) > This is most probably it. I can't do a wait because the > program I'm forking infinite-loops until I change state. > The wait() would wait infinitely. Not unless you tell it to... Use wait3 with options set to WNOHANG. If no chile processes have exited, it will just return 0 immediately. You definitely need a good book on UNIX programming; none of this is difficult, but you just cannot find this information in the man pages. > Hmm. There's got to be other ways of doing this.... Probably, there always are. You just need a few good lessons in The UNIX Way (tm) I just found this cool little snippet of code in _UNIX Network Programming_: sigchld_parent() { union wait status; int pid; again: pid = wait3(&status, WNOHANG | WUNTRACED, (struct rusage *) 0); if (pid == 0) return; goto again; } Early in your main program, you need to handle SIGCHLD with this routine: ... signal(SIGCHLD, sigchld_parent); ... This will automagically reap (and ignore) the return status of *all* child processes. Does this help? I'm certain we've gone beyone the scope of freebsd-questions now; fell free to email directly if you have more questions. -- "Where am I, and what am I doing in this handbasket?" Wes Peters Softweyr LLC http://www.xmission.com/~softweyr softweyr@xmission.com