forked from joahannes/minix
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathteste.c
More file actions
68 lines (64 loc) · 2.47 KB
/
teste.c
File metadata and controls
68 lines (64 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/time.h>
#define SEC(tv) (tv.tv_sec + tv.tv_usec/1e6)
int main(int argc, char **argv) {
struct timeval p_start, p_end, p_time;
int *pid;
unsigned long int x=1;
int num, nproc, io_ops, cpu_ops;
long int i=0;
if (argc != 4) {
printf("Uso comando: %s <num_procs> <IO_ops> <CPU_ops>"
"\n <num_procs>: numero total de processos."
"\n <IO_ops>: numero de operacoes de IO por processo"
"\n <CPU_ops>: numero de operacoes de CPU por processo\n",
argv[0]);
return 0;
}
nproc = atoi(argv[1]);
io_ops = atoi(argv[2]);
cpu_ops = atoi(argv[3]);
pid = (int *)calloc(nproc, sizeof(int));
if (!pid){
perror("calloc()");
return -1;
}
for(num=0; num<nproc; num++) {
pid[num]=fork();
if(pid[num]==0) {
// Se num for par, filho eh IO bound,
// senao, eh CPU bund
if((num % 2) == 0) {
gettimeofday(&p_start, NULL);
for(i=0; i<io_ops; i++){
fprintf(stderr, "Proc:%d i=%ld\n", num, i);
fflush(stderr);
}
gettimeofday(&p_end, NULL);
timersub(&p_end, &p_start, &p_time);
printf("IO\t %d\t %g\n",num, SEC(p_time));
} else {
gettimeofday(&p_start, NULL);
for(i=0; i<cpu_ops; i++)
{
x = (x << 4) - (x << 4);
}
gettimeofday(&p_end, NULL);
timersub(&p_end, &p_start, &p_time);
printf("CPU\t %d\t %g\n",num, SEC(p_time));
}
exit(0); // todo filho termina aqui ...
}
}
// pai apenas aguarda o termino dos filhos
for(i=0; i<nproc; i++) {
int pid_p=wait(NULL);
}
return 0;
}