Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // criacao de varios processos (fork)
- // Apple Xcode
- // paulogp
- #include <stdio.h>
- #include <unistd.h>
- #include <stdlib.h>
- #include <time.h>
- #include <signal.h>
- int main (int argc, const char * argv[])
- {
- int the_fork, i;
- for (i = 0; i < 10; ++i)
- {
- // create a new process
- the_fork = fork();
- // child process
- if (the_fork == 0)
- {
- printf("filho %d: %d\n", i + 1, getpid());
- pause(); // stop until signal
- exit(0);
- }
- }
- // wait
- sleep(2);
- // processes
- system("ps -o pid,ppid,command");
- pause(); // stop until signal
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement