Re: [ILUG] Programming problem

From: Mark Fallon (Mark.Fallon at domain oracle.com)
Date: Mon 24 Jul 2000 - 15:17:59 IST


Thomas Degris wrote:
>
> Hello, I don't know if it the right mailing list but I am trying to program
> a little thing for Linux and I get two problems.
>
> The first is I would like use the function rand and I can't find out
> (sorry, I am net very clever you know...) how I can initialize the series
> of random number with the clock or something like that. I get each time the
> same serie.
>

You use the srand(unsigned int seed) to seed the random number generator
otherwise it defaults to a seed of 1.

> My second problem is I would like run another program. So, I use :
> pid=fork();
> if (pid==1) { //maybe it's zero, I can't remember
> execv(myprogram,argv);
> exit(0);
> }
>
> The problem is when I am doing a ps to see the list of the processus, the
> program each time I run it is in the list like a zombie. How it is possible
> to finish it completely ?
>
> Thank you very much for your help.
>

I think what you are trying to do is launch a type of daemon process. To
do
this you need the exec program to call setsid, then the process that
forks
and execs your program will no longer see it as a child.

Your code should never actually reach the exit statement shown here
because
when you do the execv, the process image of the second executable is
loaded in.

Regards,

Mark

-- 
_______________________________________________________________
Mark Fallon			E-mail : Mark.Fallon at domain oracle.com
Senior Software Engineer	Phone  : +353-1-8033207
Global Product Engineering	Fax    : +353-1-8033221
_______________________________________________________________


This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:06:58 GMT