-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished first two exercises of worksheet 2
- Loading branch information
1 parent
6c4e22d
commit ab082db
Showing
2 changed files
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> /*chamadas ao sistema: defs e decls essenciais*/ | ||
#include <sys/wait.h> /*chamadas wait*() e macros relacionadas*/ | ||
|
||
int main(int argc, char const *argv[]) { | ||
pid_t pid = getpid(); | ||
pid_t ppid = getppid(); | ||
printf("The PID is %d.\nThe PPID is %d.\n",(int)pid,(int)ppid); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <stdio.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/wait.h> | ||
|
||
int main(int argc, char const *argv[]) { | ||
pid_t pid; | ||
if((pid = fork()) == 0) { | ||
pid_t childPID = getpid(); | ||
pid_t childPPID = getppid(); | ||
printf("Child PID = %d\nChild PPID = %d\n", childPID, childPPID); | ||
} | ||
else { | ||
pid_t parentPID = getpid(); | ||
pid_t parentPPID = getppid(); | ||
pid_t parentChildPID = pid; | ||
printf("Parent PID = %d\nParent PPID = %d\nChild PID from Parent = %d\n\n", parentPID, parentPPID, parentChildPID); | ||
wait(NULL); | ||
} | ||
return 0; | ||
} |