Übung 5
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
all: p1 p2 p3 p4
|
||||
|
||||
p1:
|
||||
cc -o p1 p1.c
|
||||
|
||||
p2:
|
||||
cc -o p2 p2.c
|
||||
|
||||
p3:
|
||||
cc -o p3 p3.c
|
||||
|
||||
p4:
|
||||
cc -o p4 p4.c
|
||||
|
||||
clean:
|
||||
rm -f p1 p2 p3 p4
|
||||
11
Assets/Betriebssysteme_uebung/u2-anlage/u2-a1-anlage/p1.c
Normal file
11
Assets/Betriebssysteme_uebung/u2-anlage/u2-a1-anlage/p1.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%d: code before forking - executed once only\n", getpid());
|
||||
|
||||
fork();
|
||||
|
||||
printf("%d: code after forking - executed by each process\n", getpid());
|
||||
}
|
||||
20
Assets/Betriebssysteme_uebung/u2-anlage/u2-a1-anlage/p2.c
Normal file
20
Assets/Betriebssysteme_uebung/u2-anlage/u2-a1-anlage/p2.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
if (fork() == 0)
|
||||
{ // child proc
|
||||
printf("%d: child created by parent %d; executing 'p4'...\n", getpid(), getppid());
|
||||
execl("p4", "p4", NULL);
|
||||
printf("system call execl(): no success\n");
|
||||
}
|
||||
else
|
||||
{ // parent proc
|
||||
printf("%d: parent process\n", getpid());
|
||||
}
|
||||
|
||||
wait(NULL);
|
||||
}
|
||||
22
Assets/Betriebssysteme_uebung/u2-anlage/u2-a1-anlage/p3.c
Normal file
22
Assets/Betriebssysteme_uebung/u2-anlage/u2-a1-anlage/p3.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
if (fork() == 0)
|
||||
{ // child proc
|
||||
printf("%d: child created by parent %d; executing 'p4'...\n", getpid(), getppid());
|
||||
execl("p4", "p4", NULL);
|
||||
}
|
||||
else
|
||||
{ // parent proc
|
||||
printf("%d: parent process\n", getpid());
|
||||
}
|
||||
|
||||
fork();
|
||||
printf("%d: terminating\n", getpid());
|
||||
|
||||
wait(NULL);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("%d: p4 running\n", getpid());
|
||||
}
|
||||
Reference in New Issue
Block a user