| | 111 | La procedura per finalizzare l''''intero''' esame di ''Sistemi Operativi I e II'' è riassunta di seguito: |
| | 112 | |
| | 113 | {{{ |
| | 114 | #!c |
| | 115 | #include <stdlib.h> |
| | 116 | #include <stdio.h> |
| | 117 | #include <unistd.h> |
| | 118 | #include <time.h> |
| | 119 | |
| | 120 | int solab(void) { |
| | 121 | return rand() % 31; |
| | 122 | } |
| | 123 | |
| | 124 | int teoria(void) { |
| | 125 | return rand() % 31; |
| | 126 | } |
| | 127 | |
| | 128 | int main() { |
| | 129 | int fds[2], rt, rl; |
| | 130 | printf("Iscrizione SIFA a (entrambi) Sistemi Operativi I e II\n"); |
| | 131 | pipe(fds); |
| | 132 | srand(time(NULL)); |
| | 133 | if (fork() == 0) { |
| | 134 | int r; |
| | 135 | do { |
| | 136 | sleep(rand() % 2); |
| | 137 | r = solab(); |
| | 138 | printf("Voto laboratorio: %d\n", r); |
| | 139 | } while (r < 18); |
| | 140 | write(fds[1], &r, sizeof(r)); |
| | 141 | return 0; |
| | 142 | } |
| | 143 | do { |
| | 144 | sleep(rand() % 3); |
| | 145 | rt = teoria(); |
| | 146 | printf("Voto teoria: %d\n", rt); |
| | 147 | srand(time(NULL)); |
| | 148 | } while (rt < 18); |
| | 149 | |
| | 150 | read(fds[0], &rl, sizeof(rl)); |
| | 151 | printf("Registrazione Sistemi Operativi I e II: %u \n", |
| | 152 | (unsigned int)((3.*(float)rl + 9.*(float)rt)/12.)); |
| | 153 | return 0; |
| | 154 | } |
| | 155 | |
| | 156 | }}} |
| | 157 | |
| | 158 | |