diff --git a/a.out b/chap0/a.out similarity index 52% rename from a.out rename to chap0/a.out index aa91c57..bfe2420 100755 Binary files a/a.out and b/chap0/a.out differ diff --git a/mem.c b/chap0/mem.c similarity index 100% rename from mem.c rename to chap0/mem.c diff --git a/chap0/parent.c b/chap0/parent.c new file mode 100644 index 0000000..aed337c --- /dev/null +++ b/chap0/parent.c @@ -0,0 +1,16 @@ +#include // p r i n t f +#include // e x i t ( . . ) , EXIT_SUCCESS +#include // 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 ); +} diff --git a/sig.c b/chap0/sig.c similarity index 100% rename from sig.c rename to chap0/sig.c diff --git a/chap1/a.out b/chap1/a.out new file mode 100755 index 0000000..0ba1161 Binary files /dev/null and b/chap1/a.out differ diff --git a/chap1/application-sigrt.h b/chap1/application-sigrt.h new file mode 100644 index 0000000..5bdeff7 --- /dev/null +++ b/chap1/application-sigrt.h @@ -0,0 +1,9 @@ +#ifndef __HAVE_APPLICATION_SIGRT__ +#define __HAVE_APPLICATION_SIGRT__ + +# include // SIGRTMIN + +# define SIGRT_START (SIGRTMIN +1) +# define SIGRT_FINAL ( SIGRTMIN +0) + +# endif // __HAVE_APPLICATION_SIGRT__ diff --git a/chap1/application-sigrt.h.gch b/chap1/application-sigrt.h.gch new file mode 100644 index 0000000..cae6dfc Binary files /dev/null and b/chap1/application-sigrt.h.gch differ diff --git a/chap1/canvas.c b/chap1/canvas.c new file mode 100644 index 0000000..6e87987 --- /dev/null +++ b/chap1/canvas.c @@ -0,0 +1,50 @@ +#include // e x i t ( . . ) , EXIT_SUCCESS +#include "application-sigrt.h" +#include +#include +#include + + +#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 ); +} diff --git a/chap1/ex1.c b/chap1/ex1.c new file mode 100644 index 0000000..0de8ef8 --- /dev/null +++ b/chap1/ex1.c @@ -0,0 +1,58 @@ +#include // e x i t ( . . ) , EXIT_SUCCESS +#include "application-sigrt.h" +#include +#include +#include + + +#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 ); +} diff --git a/chap1/modif.txt b/chap1/modif.txt new file mode 100644 index 0000000..5dfa9d7 --- /dev/null +++ b/chap1/modif.txt @@ -0,0 +1,3 @@ +requested.tv_nsec = 45e7 +pas usec +vasue = value