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

Re: script timer



Chakrabarti, Suvendra (CTS) forced the electrons to say:
>      Hi Binand,
> 
>      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.

Hmm... Have you seen the sleep(3) man page? It says (not in so many words,
I admit) that sleep is implemented in exactly the same way (using SIGALRM,
assuming that is the signal you meant). I think Stevens' book on Unix
system programming also has an implementation of sleep this way.

I admit that sleep() has a bunch of problems associated, mainly setjmp.h
functions, and SIGALRM.  Maybe a better way to do this will be using
the select(2) system call to avoid all the problems of sleep.

>      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.

system (command) also does the same thing! And it has got an additional bunch
of security related problems associated with it. execl() or execv() are the
recommended ones by unix gurus.

Binand

- -- 
#include <stdio.h>                                   | Binand Raj S.
char *p = "#include <stdio.h>%cchar *p = %c%s%c;     | This is a self-
int main(){printf(p,10,34,p,34,10);return 0;}%c";    | printing program.
int main(){printf(p,10,34,p,34,10);return 0;}        | Try it!!
- --------------------------------------------------------------------
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.

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