-
Notifications
You must be signed in to change notification settings - Fork 1
/
5-1.c
78 lines (68 loc) · 1.07 KB
/
5-1.c
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
69
70
71
72
73
74
75
76
77
78
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <math.h>
#include <time.h>
#define MAX 23500
void funcion(int pid){
int cuentaS = 500;
int cuentaC = 500;
int i = 0;
int seno;
int coseno;
int tangente;
int logaritmo;
int raiz;
int j;
srand(pid);
int random;
while(cuentaC > 0 && cuentaS > 0){
random = rand()%2;
switch(random){
case 0://sleep
if(cuentaS>0){
//printf("%d Estoy en sleep\n",getpid());
usleep(10);
cuentaS--;
}
break;
case 1://calculos
if(cuentaC>0){
//printf("%d Estoy haciendo calculos\n",getpid());
while(i<MAX){
seno += sin(i);
coseno += cos(i);
tangente += tan(i);
logaritmo += log(i);
raiz += sqrt(i);
i++;
}
i = 0;
cuentaC--;
}
break;
}
}
}
int main(){
pid_t pid;
int random;
int estado;
int j;
//srand(time(NULL));
/*for(j = 0; j < 4; j++){
pid = fork();
if(pid == 0)
break;
}
if(pid > 0){
wait(&estado);
//exit(0);
}
else{*/
//funcion(getpid());
funcion()
exit(0);
//}
return 0;
}