Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // exame de recurso (parte a): 2009-09-29
- // exercicio 2: fork, output de valores
- // Apple Xcode
- // paulogp
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- int main (int argc, const char * argv[])
- {
- pid_t pid;
- int counter = 5;
- int *p = &counter;
- pid = fork();
- if (pid == 0)
- {
- printf("%d\n", counter);
- *p = 1;
- printf("%d\n", counter);
- }
- else
- {
- wait(NULL);
- printf("%d\n", *p);
- }
- return 0;
- }
- /* output
- 5
- 1
- 5
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement