P09 lab code added

This commit is contained in:
Andreas Gieriet
2020-04-26 15:02:50 +02:00
parent 94945069e3
commit f4c374887c
45 changed files with 2116 additions and 0 deletions
@@ -0,0 +1,51 @@
//***************************************************************************
// File: ProcA6.c
// Original Author: M. Thaler (Modul BSY)
//***************************************************************************
//***************************************************************************
// system includes
//***************************************************************************
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
//***************************************************************************
// Function: main(), parameter: none
//***************************************************************************
int main(void) {
pid_t pid, id;
char buf[64];
int i;
pid = fork();
switch (pid) {
case -1:
perror("Could not fork");
break;
case 0:
printf("\n... ich bin das Kind %d\n", getpid());
for (i = 0; i < 10; i++) {
usleep(500000); // slow down a bit
printf("Mein Elternprozess ist %d\n", id = getppid());
}
printf("... so das wars\n");
break;
default:
sleep(2); // terminate
exit(0);
break;
}
printf("\n\n*** and here my new parent ****\n\n");
sprintf(buf, "ps -p %d", id);
system(buf);
exit(0);
}
//***************************************************************************
@@ -0,0 +1,3 @@
Reparenting -> new parent instead init (1):
command prctl(PR_SET_CHILD_SUBREAPER, 1)
@@ -0,0 +1,26 @@
# *************************************************************
# Original Autor: M. Thaler (Modul BSY)
# *************************************************************
CMP= gcc
CMPFLAGS= -Wall
LDFLAGS=
EXENAMES= ProcA5.e
FNAME= ProcA5
LIBNAME=
$(EXENAMES): $(FNAME).o
$(CMP) $(FNAME).o $(LIBNAME) $(LDFLAGS) -o $@
.c.o:
$(CMP) -c $(CMPFLAGS) $<
.cc.o:
$(CMP) -c $(CMPFLAGS) $<
clean:
rm -f *.o $(EXENAMES)
all:
@make clean
@make