Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "assert.h"
- #include "unistd.h"
- #include "pthread.h"
- #include "wait.h"
- void* thready_function()
- {
- sleep(10);
- printf("Now I am ending!\n");
- return 0;
- }
- int main()
- {
- pthread_t thready;
- int pid = fork();
- if (pid == 0)
- {
- int pid_child = fork();
- if (pid_child == 0)
- {
- for (int i = 0; i < 10; i++)
- printf("The inner child is printing!\n");
- assert((pthread_create(&thready, NULL, &thready_function, NULL) == 0) && "This should never happen!\n");
- pthread_join(thready, NULL);
- }
- else
- {
- waitpid(pid_child, NULL, NULL);
- printf("The child waited for %d!\n", pid_child);
- for (int i = 0; i < 10; i++)
- printf("The child is printing!\n");
- }
- }
- else
- {
- waitpid(pid, NULL, NULL);
- printf("The parent waited for %d!\n", pid);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement