Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/types.h>
- #include <unistd.h>
- #include <signal.h>
- void oldman() {
- fprintf(stdout, "I'm not yet dead! My ID is %i\n", (int)getpid());
- }
- void recreation() {
- fprintf(stdout, "Who I am? My ID is %i\n", (int)getpid());
- }
- int main() {/*
- pid_t child_pid, parent_pid;
- int i = 0;
- fprintf(stdout,"Before RECREATION %i\n",parent_pid = (int)getpid());
- child_pid = fork();
- while(i++ < 5)
- if (child_pid!=0)
- oldman();
- else recreation();*/
- pid_t child_pid, parent_pid;
- double s = 0.0;
- parent_pid = (int)getpid();
- child_pid = fork();
- fork();
- fork();
- //kill(child_pid, SIGKILL);
- fprintf(stdout, "PARENT: %i\nCHILD: %i\n", parent_pid, child_pid);
- pause();
- if(child_pid != parent_pid) {
- s += 3.14;
- fprintf(stdout, "CHILD: %i s=%g &s=%f\n", (int)getpid(), s, &s);
- }else
- {
- s += 2.72;
- fprintf(stdout, "PARENT: %i s=%g &s=%f\n", (int)getpid(), s, &s);
- }
- return (EXIT_SUCCESS);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement