This commit is contained in:
Super_JK
2022-03-29 17:17:15 +02:00
parent 43718037d2
commit bd84de1a32
10 changed files with 136 additions and 0 deletions

Binary file not shown.

View File

16
chap0/parent.c Normal file
View File

@@ -0,0 +1,16 @@
#include <stdio.h> // p r i n t f
#include <stdlib.h> // e x i t ( . . ) , EXIT_SUCCESS
#include <unistd.h> // f o r k ( ) , getpid ( )
int main ( int argc , char * argv []) {
pid_t fvalue = fork ();
if ( fvalue != 0) {
// Parent process
printf("[%ld] I am your father , %ld!\n " , getpid () , fvalue );
} else {
// Child process
printf("[%ld] Nooooooooooooooo ! (%ld)\n " , getpid () , fvalue );
}
exit ( EXIT_SUCCESS );
}

View File

BIN
chap1/a.out Executable file

Binary file not shown.

View File

@@ -0,0 +1,9 @@
#ifndef __HAVE_APPLICATION_SIGRT__
#define __HAVE_APPLICATION_SIGRT__
# include <signal.h> // SIGRTMIN
# define SIGRT_START (SIGRTMIN +1)
# define SIGRT_FINAL ( SIGRTMIN +0)
# endif // __HAVE_APPLICATION_SIGRT__

Binary file not shown.

50
chap1/canvas.c Normal file
View File

@@ -0,0 +1,50 @@
#include <stdlib.h> // e x i t ( . . ) , EXIT_SUCCESS
#include "application-sigrt.h"
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#define __START__ 0
#define EXPECTING 1
#define OPERATING 2
#define __FINAL__ 3
sigset_t mask ;
volatile sig_atomic_t state = __START__ ;
void handleStart ( int signum , siginfo_t * info , void * context ) {
state = OPERATING ;
sigaddset (& mask , SIGRT_START );
sigprocmask ( SIG_SETMASK , & mask , NULL );
}
void handleFinal ( int signum , siginfo_t * info , void * context ) {
state = __FINAL__ ;
sigaddset (& mask , SIGRT_FINAL );
sigprocmask ( SIG_SETMASK , & mask , NULL );
}
int main ( int argc , char * argv []) {
sigfillset (& mask );
sigprocmask ( SIG_SETMASK , & mask , NULL );
struct sigaction descriptor ;
memset(& descriptor , 0 , sizeof ( descriptor ));
descriptor.sa_flags = SA_SIGINFO ;
descriptor.sa_sigaction = handleStart ;
sigaction ( SIGRT_START , & descriptor , NULL );
descriptor.sa_sigaction = handleFinal ;
sigaction ( SIGRT_FINAL , & descriptor , NULL );
state = EXPECTING ;
sigdelset (& mask , SIGRT_START );
sigprocmask ( SIG_SETMASK , & mask , NULL );
while ( state == EXPECTING )
pause();
sigdelset (& mask , SIGRT_FINAL );
sigprocmask ( SIG_SETMASK , & mask , NULL );
while ( state == OPERATING ) {
// Working on something . . .
printf("f");
}
exit ( EXIT_SUCCESS );
}

58
chap1/ex1.c Normal file
View File

@@ -0,0 +1,58 @@
#include <stdlib.h> // e x i t ( . . ) , EXIT_SUCCESS
#include "application-sigrt.h"
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#define __START__ 0
#define EXPECTING 1
#define OPERATING 2
#define __FINAL__ 3
sigset_t mask ;
volatile sig_atomic_t state = __START__ ;
void handleStart ( int signum , siginfo_t * info , void * context ) {
state = OPERATING ;
sigaddset (& mask , SIGRT_START );
sigprocmask ( SIG_SETMASK , & mask , NULL );
}
void handleFinal ( int signum , siginfo_t * info , void * context ) {
state = __FINAL__ ;
sigaddset (& mask , SIGRT_FINAL );
sigprocmask ( SIG_SETMASK , & mask , NULL );
}
int main ( int argc , char * argv []) {
pid_t fvalue = fork();
if (fvalue != 0){
sigfillset (& mask );
sigprocmask ( SIG_SETMASK , & mask , NULL );
struct sigaction descriptor ;
memset(& descriptor , 0 , sizeof ( descriptor ));
descriptor.sa_flags = SA_SIGINFO ;
descriptor.sa_sigaction = handleStart ;
sigaction ( SIGRT_START , & descriptor , NULL );
descriptor.sa_sigaction = handleFinal ;
sigaction ( SIGRT_FINAL , & descriptor , NULL );
state = EXPECTING ;
sigdelset (& mask , SIGRT_START );
sigprocmask ( SIG_SETMASK , & mask , NULL );
while ( state == EXPECTING )
pause();
sigdelset (& mask , SIGRT_FINAL );
sigprocmask ( SIG_SETMASK , & mask , NULL );
while ( state == OPERATING ) {
// Working on something . . .
printf("f");
}
} else {
}
exit ( EXIT_SUCCESS );
}

3
chap1/modif.txt Normal file
View File

@@ -0,0 +1,3 @@
requested.tv_nsec = 45e7
pas usec
vasue = value