Re: FreeBSD & Linux

Hans Eric =?ISO-8859-1?Q?Sandstr=F6m (hes@xinit.se)
Tue, 03 Nov 1998 14:54:16 +0100


Sher Pavel A. wrote:

> Can somebody tell me why this program under FreeBSD works much more faster
> then under Linux ?
>
> #include <stdio.h>
> #include <unistd.h>
> #include <time.h>
> #include <stdlib.h>
> #include <sys/types.h>
> #include <signal.h>
>
> void main(int argc, char *argv[])
> {
> unsigned int num, i, st;
> time_t new_time, old_time;
> int *pid;
>
> if (argc < 2) {
> printf("Usage: fork nnn\n");
> _exit(0);
> }
> num=atoi(argv[1]);
> pid=malloc(sizeof(int)*num);
> old_time=time(NULL);
> for (i=0; i<num; i++) {
> st=fork();
> if (st == 0) {
> while (1);

What the f(/%¤&(uck are you dong here. All child processed are in one hell of a cpu eating
loop. The only thing you end up measuring is how fair ths timesilceas are handed out
between different processes. Freebsd seems to favor the parent process and thus can fork
and then kill the childs faster. Liniux is more fair and gives the cpu eatimg childs time
and thus the total time gets longer. Try puttin in a sleep here...
Replace the above with:
while(1) sleep(1);

And then redo yor tests...

>
> _exit(0);
> }
> pid[i]=st;
> printf("Process %i started.\n", i);
> }
> for (i=0; i<num; i++) {
> kill(pid[i], SIGKILL);
> printf("Process %i killed.\n", i);
> }
> new_time=time(NULL);
> printf("Total time to spawn and kill %i processes : %i\n", num, new_time-old_time);
> }
>
> FreeBSD: ./fork 100 - 20 seconds
> Linux: ./fork 100 - 204 seconds on kernel 2.0.35
> and 220 seconds on kernel 2.1.126
>
> FreeBSD: AMD486-133MHz, 32Mb RAM
> Linux: iP133, 32Mb RAM
>
> P.S:
> Sorry for my english.
>
> ------------------------------------------
> Sher A. Pavel
> e-mail: pavel@lime.hop.stu.neva.ru
>
> Why use windows since there is a door ?
> Anonym.
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.rutgers.edu
> Please read the FAQ at http://www.tux.org/lkml/

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/