37 lines
1.0 KiB
C
37 lines
1.0 KiB
C
//////////////////////////////////////////////////////////////////////////////
|
|
// Course: Real Time Systems
|
|
// Lecturer: Dr.-Ing. Frank Golatowski
|
|
// Exercise instructor: M.Sc. Michael Rethfeldt
|
|
// Exercise: 1
|
|
// Task: 2
|
|
// Name: aufgabe2.c
|
|
// Description: ?
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
int main(void)
|
|
{
|
|
int status;
|
|
pid_t fork_pid;
|
|
|
|
if ( (fork_pid=fork() ) == 0 )
|
|
{
|
|
printf("* I am the son. *\n");
|
|
exit(3);
|
|
}
|
|
else if (fork_pid == -1)
|
|
{
|
|
printf("fork() failed!\n");
|
|
exit(2);
|
|
}
|
|
wait(&status); // wait for termination of son process
|
|
// status: hexa decimal output from son process
|
|
// (status>>8) & 0xff: second (higher byte) of the status
|
|
// status & 0xff: first (lower byte) of the status
|
|
printf("wait status: 0x%x | 0x%x | 0x%x |\n", status, (status>>8) & 0xff, status & 0xff);
|
|
return 0;
|
|
}
|