Übung 5
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
all: p5 p6 p7
|
||||
|
||||
p5:
|
||||
gcc -o p5 p5.c
|
||||
|
||||
p6:
|
||||
gcc -o p6 p6.c
|
||||
|
||||
p7:
|
||||
gcc -o p7 p7.c
|
||||
|
||||
clean:
|
||||
rm -f p5 p6 p7
|
||||
23
Assets/Betriebssysteme_uebung/u2-anlage/u2-a2-anlage/p5.c
Normal file
23
Assets/Betriebssysteme_uebung/u2-anlage/u2-a2-anlage/p5.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
int pid;
|
||||
|
||||
pid = fork();
|
||||
|
||||
if (pid == 0)
|
||||
{ // child proc looping endlessly
|
||||
printf("%d: child ...\n", getpid());
|
||||
for(;10;);
|
||||
}
|
||||
else
|
||||
{ // parent proc
|
||||
printf("%d: parent; child pid: %d \n", getpid(), pid);
|
||||
wait(NULL); // for child termination
|
||||
printf("%d: parent after wait ... terminating\n", getpid());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("p6: calling getchar()\n");
|
||||
getchar();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("p7: calling sleep()\n");
|
||||
sleep(100);
|
||||
}
|
||||
Reference in New Issue
Block a user