Rev | Line | |
---|
[13] | 1 | #include <lib.h>
|
---|
| 2 | #include <unistd.h>
|
---|
| 3 | #include <stdlib.h>
|
---|
| 4 | #include <stdio.h>
|
---|
| 5 |
|
---|
| 6 | int up(void)
|
---|
| 7 | {
|
---|
| 8 | message m;
|
---|
| 9 |
|
---|
| 10 | if (_syscall(SS_PROC_NR, SS_UP, &m) < 0) return(-1);
|
---|
| 11 | return 0;
|
---|
| 12 | }
|
---|
| 13 |
|
---|
| 14 | int down(void)
|
---|
| 15 | {
|
---|
| 16 | message m;
|
---|
| 17 |
|
---|
| 18 | if (_syscall(SS_PROC_NR, SS_DOWN, &m) < 0) return(-1);
|
---|
| 19 | return 0;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | int main(void)
|
---|
| 23 | {
|
---|
| 24 | /* grazie al semaforo, il padre stampa sempre prima del figlio */
|
---|
| 25 | int r=0;
|
---|
| 26 | if (fork() > 0){
|
---|
| 27 | /* padre */
|
---|
| 28 | sleep(10);
|
---|
| 29 | printf("Sono il padre\n");
|
---|
| 30 | r = up();
|
---|
| 31 | if (r<0) printf("Errore p:%d\n", r);
|
---|
| 32 | return 0;
|
---|
| 33 | } else {
|
---|
| 34 | /* figlio */
|
---|
| 35 | r = down();
|
---|
| 36 | if (r<0) printf("Errore f:%d\n", r);
|
---|
| 37 | printf("Sono il figlio\n");
|
---|
| 38 | return 0;
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.