Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <sys/wait.h>
- #include <sys/types.h>
- #include <errno.h>
- int main()
- {
- pid_t pid;
- /* wypisuje ID procesu */
- printf("Moj PID = %d\n", getpid());
- /* tworzy nowy proces */
- switch(pid = fork())
- {
- case -1: /* blad */
- printf("Error in fork = %d %s\n", errno, strerror(errno));
- case 0: /* proces potomny */
- {
- printf("Jestem procesem potomnym. Moj PID = %d\n", getpid());
- printf("Jestem procesem potomnym. Wartosc przekazana przez fork() = %d\n", pid);
- return 0;
- }
- default: /* proces macierzysty */
- {
- printf("Jestem procesem macierzystym. Moj PID = %d\n", getpid());
- printf("Jestem procesem macirzysytm. Wartosc przekazana przez fork = %d\n", pid);
- }
- /* czeka na zakonczenie procesu potomnego */
- /* aby zobaczyc ZOMBI - sleep */
- // sleep(10);
- if(wait(0) == -1)
- {
- printf("Error in wait = %d %s\n", errno, strerror(errno));
- return 0;
- }
- } // switch
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement