P09 lab code added
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
//***************************************************************************
|
||||
// File: ProcA1.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;
|
||||
int status;
|
||||
int i;
|
||||
|
||||
i = 5;
|
||||
|
||||
printf("\n\ni vor fork: %d\n\n", i);
|
||||
|
||||
pid = fork();
|
||||
switch (pid) {
|
||||
case -1:
|
||||
perror("Could not fork");
|
||||
break;
|
||||
case 0:
|
||||
i++;
|
||||
printf("\n... ich bin das Kind %d mit i=%d, ", getpid(),i);
|
||||
printf("meine Eltern sind %d \n", getppid());
|
||||
break;
|
||||
default:
|
||||
i--;
|
||||
printf("\n... wir sind die Eltern %d mit i=%d ", getpid(), i);
|
||||
printf("und Kind %d,\n unsere Eltern sind %d\n", pid, getppid());
|
||||
wait(&status);
|
||||
break;
|
||||
}
|
||||
printf("\n. . . . . und wer bin ich ?\n\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# *************************************************************
|
||||
# Original Autor: M. Thaler (Modul BSY)
|
||||
# *************************************************************
|
||||
|
||||
CMP= gcc
|
||||
CMPFLAGS= -Wall
|
||||
LDFLAGS=
|
||||
EXENAM1= ProcA1.e
|
||||
FNAM1= ProcA1
|
||||
LIBNAME=
|
||||
|
||||
$(EXENAM1): $(FNAM1).o
|
||||
$(CMP) $(FNAM1).o $(LIBNAME) $(LDFLAGS) -o $@
|
||||
|
||||
.c.o:
|
||||
$(CMP) -c $(CMPFLAGS) $<
|
||||
|
||||
.cc.o:
|
||||
$(CMP) -c $(CMPFLAGS) $<
|
||||
|
||||
clean:
|
||||
rm -f *.o $(EXENAM1)
|
||||
|
||||
all:
|
||||
@make clean
|
||||
@make
|
||||
Reference in New Issue
Block a user