FreeBSD & Linux

Sher Pavel A. (pavel@lime.hop.stu.neva.ru)
Wed, 11 Nov 1998 04:41:21 +0300 (MSK)


Thank you for you answers. I didn`t test my program with ./fork
1000 because it should take too much time for my system. That is why I
couldn`t see the bug with pid == -1. Now I think that my new "test"
written better then previous. But please don`t run this under root !

#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/ipc.h>
#include <sys/shm.h>

int flag=0;

void catch(int signum)
{
flag=1; // set flag=1 if catch signal SIGUSR1
}

void main(int argc, char *argv[])
{
unsigned int num, i, j, st, rnum=0, total=0, my_work=0;
time_t new_time, old_time, old2_time;
int *pid, status, shmid;
unsigned int *work;

if (argc < 2) {
printf("Usage: fork nnn\n");
_exit(0);
}
num=atoi(argv[1]);
pid=malloc(sizeof(int)*num);
// create share memory segment (if can`t create or segment with key=100 already exists then exit)
shmid=shmget(100, sizeof(unsigned int)*num, IPC_CREAT | IPC_EXCL | 0644);
if (shmid == -1) { perror("shmget"); _exit(1); }
work=(unsigned int *)shmat(shmid, 0, 0);
old_time=time(NULL);
for (i=0; i<num; i++) {
st=fork();
if (st == 0) {
signal(SIGUSR1, catch);
while (!flag) my_work++; //increment work while not receive SIGUSR1
work[i]=my_work;
_exit(0);
}
if (st != -1) {
printf("%i: process %i started.\n", i, pid[i]);
pid[rnum]=st;
rnum++;
}
else printf("Failed to start process !\n");
}
new_time=time(NULL);
printf("Time to spawn %i processes: %i seconds, speed: %g Proc/sec\n", rnum, new_time-old_time, (float)rnum/(new_time-old_time));
old2_time=time(NULL);
// now we will send SIGUSR1 for every working process
for (i=0; i<rnum ; i++) {
kill(pid[i], SIGUSR1); // send SIGUSR1 to process
waitpid(pid[i], NULL, 0); // wait for dead
printf("%i: process %i dead with work: %i Kcounts\n", i, pid[i], work[i]/1000);
total += work[i]/1000; // add work to total
}
new_time=time(NULL);
shmdt(work);
status=shmctl(shmid, IPC_RMID, NULL); // mark share memory segment for remove
if (status == -1) perror("shmctl");
printf("Time spent in send signal and wait for dead %i processes: %i seconds, speed: %g Proc/sec\n", rnum, new_time-old2_time, (float)rnum/(new_time-old2_time));
printf("Total work %i Kcounts.\n", total);
printf("Power: %g Kcounts/sec\n", (float)total/(new_time-old_time));
free(pid);
}

Results:
1. AmdK5-75 with 32Mb under Linux kernel 2.0.35 (samba, DNS, news, mail,
web server) loadavg=0.10
./fork 60
0: process 14389 started.
1: process 14390 started.
...............................
59: process 14449 started.
Time to spawn 60 processes: 36 seconds, speed: 1.66667 Proc/sec
0: process 14389 dead with work: 16557 Kcounts
1: process 14390 dead with work: 18827 Kcounts
..............................................
59: process 14449 dead with work: 370 Kcounts
Time spent in send signal and wait for dead 60 processes: 12 seconds, speed: 5 Proc/sec
Total work 577357 Kcounts.
Power: 12028.3 Kcounts/sec

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

2. iP133 with 32Mb under Linux kernel 2.0.35 loadavg=0.00
./fork 60
0: process 1350 started.
1: process 1351 started.
..............................
59: process 1409 started.
Time to spawn 60 processes: 22 seconds, speed: 2.72727 Proc/sec
0: process 1350 dead with work: 20307 Kcounts
1: process 1351 dead with work: 28796 Kcounts
...............................................
58: process 1408 dead with work: 4639 Kcounts
59: process 1409 dead with work: 4639 Kcounts
Time spent in send signal and wait for dead 60 processes: 24 seconds, speed: 2.5 Proc/sec
Total work 1014960 Kcounts.
Power: 22064.3 Kcounts/sec

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

3. Amd586-133 with 32Mb under FreeBSD ver 2.2.5 loadavg=0.00
./fork 60
0: process 831 started.
1: process 832 started.
..........................
59: process 890 started.
Time to spawn 60 processes: 4 seconds, speed: 15 Proc/sec
0: process 831 dead with work: 2168 Kcounts
1: process 832 dead with work: 2278 Kcounts
...................................................
58: process 889 dead with work: 29534 Kcounts
59: process 890 dead with work: 29047 Kcounts
Time spent in send signal and wait for dead 60 processes: 81 seconds, speed: 0.740741 Proc/sec
Total work 921502 Kcounts.
Power: 10841.2 Kcounts/sec

FreeBSD takes more time for send signals and wait for dead then Linux,
but total "work" greater then in Linux. The "power" ( work/sec = power :)
in FreeBSD less then in Linux (first test) on 1200 Kcounts/sec, but
AmdK5-75 != Amd586-133 and I can`t say that Linux more "powerfull" then
FreeBSD (I can`t test this program on the same machine).
I understand that this program stays far from right test. But maybe
this results will be interesting.

P.S.:
I know, my english very bad :(

---------------------------------------------------------
Sher Pavel A.
Student of Saint-Petersburg State Technical University
Computer Science and Engineering Faculty
Automation Control System Chair
e-mail: pavel@lime.hop.stu.neva.ru

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