#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>

#define _sleep nanosleep((const struct timespec[]){{0, 25000000L}}, NULL);
#define _load 5000
#define _work { float a=3.1415,b=2.1234; int i,j; for (i=0;i<_load;i++) for (j=0;j<_load;j++) a = a*i+b*j;  }

int main () {
  int counter;
  char output;
  struct timeval tv1, tv2;
  gettimeofday(&tv1, NULL);

  if (fork()) {
    output = 'a';
    nice (-19);
  } else {
    output = 'b';
    nice (19);
  }

  fork(); fork(); fork();

  for (counter = 0; counter < 100; counter++) {
    // printf ("%c", output); fflush (NULL);
    _work;
    // _sleep; 
  }

  gettimeofday(&tv2, NULL);
  double time_spent = (tv2.tv_usec - tv1.tv_usec) / 1000000.0
                    + (tv2.tv_sec  - tv1.tv_sec);
  printf ("%c:done, time: %f\n", output, time_spent); exit (0);
}

