UNIX question

Rick Kimball kimball at bsdpkh.UUCP
Sun Dec 22 02:32:50 AEST 1985


> My question: Is there any way to kill off these zombies so I can get
> 	     more processes ?  Or, failing that, is there any other
> 	     way to do what I want ?
>
> Philip Schneider                               
> University of Washington Computer Science                
> pjs@{uw-june.arpa,washington.arpa}                      
> {ihnp4,decvax,cornell}!uw-beaver!uw-june!pjs           

If the return code from the child isn't important the following code 
will show you how to have a "fork-a-thon". 

--------- Cut Here ------

/* fork example ( parent doesn't care about child's return codes ) */

#include <stdio.h>
#include <signal.h>

#define CLS "\033[H\033[2J"       /* clear screen for vt100 */

main(argc,argv)
int   argc;
char   *argv[];
{
   int   Processes_forked,
         len,
         random_line,
         pid;
   char   message_buffer[80];

   signal(SIGCLD, SIG_IGN);

   write(1,CLS,strlen(CLS));

   while ( 1 ) {
      pid = fork();
      switch(pid) {
      case -1:         /* fork failed no process created   */
            len = sprintf(message_buffer,
                  "\033[24;0Htoo many");
            write(1,message_buffer,len);
            sleep(10);
            break;
      case 0:         /* child process                      */
            pid=getpid();
            random_line = pid % 22;
            len = sprintf(message_buffer, "\033[%d;0H#%5d", random_line, pid);
            write(1,message_buffer,len);
            sleep(2);
            len = sprintf(message_buffer, "\033[%d;0H      ", random_line);
            write(1,message_buffer,len);
            exit();
      default:         /* parent process                     */
            len = sprintf(message_buffer, "\033[24;0H%d forked",
               ++Processes_forked);
            write(1,message_buffer,len);
            break;
      }
   }
}
-------- Cut Here ----------
Rick Kimball 
UUCP: ihnp4!bsdpkh!kimball



More information about the Comp.unix mailing list