[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

RE: script timer



     Hi Binand,

     Only zombies are not left as exercise here. ;-)

     1. sleep(5) is not a very good option. This command will keep the
system resources
         busy. A better alternative will be trapping the signal SIG_ALARM.

     2. Trying to fork() every 5 seconds and spawning a new process !!! That
is
         not decent in any sense. A simple system("cmd_line") should have
         sufficed in this case, assuming the program does not take more than
         5 seconds to execute.

         OK, can we leave these also as exercises ? *sorry Binand, not for
you*

         Suvendra

> -----Original Message-----
> From:	Binand Raj S. [SMTP:binand@xxxxxxxxxxxxxxxxxxxxx]
> Sent:	Saturday, August 07, 1999 3:55 PM
> To:	linux-india@xxxxxxxxx
> Subject:	Re: script timer
> 
> #include <stdio.h>
> #include <stdlib.h>
> #include <unistd.h>
> 
> int main (void)
> {
> 	while (1)
> 	{
> 		switch (fork())
> 		{
> 			case -1: perror ("fork"); exit (EXIT_FAILURE);
> 			case 0: execl ("/home/myfile", "myfile", NULL); exit
> (EXIT_FAILURE);
> 			default: sleep(5);
> 		}
> 	}
> 	exit (EXIT_SUCCESS);
> }
> 
> There are a few other issues, like avoiding zombies, which I leave as an
> exercise to you. ;-)
> 
> Binand
> 
- --------------------------------------------------------------------
For more information on Linux in India visit http://www.linux-india.org/
The Linux India mailing list does not accept postings in HTML format.

------------------------------