timers, forking processes

timers, forking processes

Post by Paul Frette » Tue, 25 Nov 1997 04:00:00

I am trying to achieve a simple thing,
I want to write a small function  to pause for a given number of seconds
within a C program.  To do this
I am trying to use setitimer and pause().
This method works well in a simple program, but, if I try to do this in a
forked process It pauses indefinatley, It would appear that either the
parent process continually resets the timer, or the child process cannot
maintain its own timer.
The problem is illustrated by the following code:
struct itimerval MyTVal, MyOTVal, Test;
long x=0;
        setitimer(ITIMER_REAL, &MyTVal, &MyOTVal);
        for (x=1;x<100000;x++)
            getitimer(ITIMER_REAL, &Test);
            printf("Sleep value %d %d \n",  Test.it_interval.tv_sec,

In a normal program the printf sucessfully prints the values as expected,
but from a forked process
All I get is "0 0 "
What is going on?


1. Why <defunct> process after leaving a fork()ed process?

Hallo everybody!

I have a problem concerning forking processes. I have a main
program where the user may select some pushbuttons to start
another application. Everything works fine, except that after
leaving one of the 'model' applications, ps still shows the
process number, but as <defunct>. I'm running SUN OS 4.1.3. How do
I get rid of the process? After some starting and leaving
of 'child' applications the list of <defunct> processes might
get quite long.

What am I missing?
                Thanx in advance

and leaving one again

 7950 p3 IW    0:00 Parent
 7951 p3 IW    0:00 model model
 7952 p3 IW    0:00 model model
 7953 p3 Z     0:00 <defunct>

Source code
        if ((pid = fork()) < 0)
           return -1;

        if (pid > 0)
           /* The parent */
           fprintf(stderr, "PID = %d\n", pid);
        if (pid == 0)
           /* The child */
           execlp("model", "model", "model", NULL);

  Christian Steinebach
  Division of Marine Operation
  POST  : MARINTEK, P.O.Box 4125 Valentinlyst, N-7002 TRONDHEIM, Norway
  TEL   : +47 7359 5916
  FAX   : +47 7359 5778

2. xalan.jar problem with tomcat 4 ...

3. passing stdin to a forked process, after writing some data to the process ..

4. Does anyone have 2 Nics and a cable modem working with Linux ?

5. forked child process remains in process table

6. Help!Java in Linux

7. comsat forking, forking and forking (3.2.0)

8. HD w/ cylinders greater than 1024

9. Q:How to implement multiple timers in a single process

10. Process timers

11. Multiple Timers Per Process

12. Scheduling of processes, and timers

13. process timer bug in multi-processor LINUX