Announcement

Collapse
No announcement yet.

[os] exam 2 - 3 childer - fibonacci - SIGINT handler

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • [os] exam 2 - 3 childer - fibonacci - SIGINT handler

    PHP Code:
    #include <st***.h>
    #include <stdlib.h>
    #include <signal.h>

    /*
     *               _            _                          
     *              (_)          (_)                          
     *    __  ____ _ _  _____   ___  ___   ___ ___  _ __ ___  
     *    \ \/ / _` | |/ _ \ \ / / |/ _ \ / __/ _ \| '_ ` _ \
     *     >  < (_| | | (_) \ V /| | (_) | (_| (_) | | | | | |
     *    /_/\_\__, |_|\___/ \_/ |_|\___(_)___\___/|_| |_| |_|
     *          __/ |                                        
     *         |___/
     *
     *         Giovanni Di Grezia - 0512101xxx
     *
     *         ////// SECONDA PROVA INTERCORSO //////
     *
     *         Advanced Edition
     *
     *
     *        
     */

    int fibonacci int i) {
        
        if ( 
    <= 1){ return 0;} else { if ( == 2) { return 1; } else {
        
            return (
    fibonacci1) + fibonacci 2));
        
            }  
        }
        
    }

    void null_action (int signal) {}


    void action int signal) {
        
        
    int pid,statuschar character;
        
    pid fork();
        
        if ( 
    pid == -1) { exit(-2);} else {
            
            if ( 
    pid == 0) {
                
                
                
    fprintf stdout"Pid padre %d \n"getppid());
                
    fprintf(stdout"Terminare?\n");
                
    fscanf(stdin,"%c",&character);
                
                if (
    character == 'y'){
                    
                    
    kill (getppid(),SIGKILL);
                    
    kill (getpid(),SIGKILL);
                    
                } else {
                
                   
    kill getppid(),SIGCONT);
                    
                }

                exit(
    0);
            } else {
                
    kill getpid(),SIGSTOP);
                
    waitpid(-1,&status,0);
              
            }
        }
        
    }


    int main void ){
        
        
        
    int pid,i,status,err;
        
        
    struct sigaction sigintaction;
            
    sigintaction.sa_handlernull_action;
            
    sigintaction.sa_flags=0;
            
        
    sigaction (SIGINT, &sigintactionNULL);
        
        
    pid=fork();
        
        
        if ( 
    pid == -) { /* errore */ exit(-1);} else {
            
            if ( 
    pid == 0){
                
                
    sigintaction.sa_handleraction;
                
    sigaction (SIGINT, &sigintactionNULL);
                
                
    struct sigaction sigusr1action;
                
    sigusr1action.sa_handlernull_action;
                
    sigusr1action.sa_flags=0;
            
                
    sigaction (SIGUSR1, &sigusr1actionNULL);
                
                
                for (
    i=0;i<300;i++){
                    
                        
    fprintf(stdout,"Fib %d\n"fibonacci(i+1));
                    
                }
                
            } else {
                
    errwaitpid(-1,&status,0);
                for (;
    err != pid;){
                    
    errwaitpid(-1,&status,0);
                }
                
    fprintf(stdout,"Figlio con pid %d terminato\n",pid);  
            }
                    
        }

        return 
    0;

    | VFX Artist, C++ Programmer, HW Overclocker | Web: xgiovio.com Email: xgiovio@gmail.com Twitter: @xgiovio
Working...
X

Google Profile


My name is Giovanni Di Grezia, but people call me xgiovio.

Here is my homepage:.

I'm a VFX Artist and Software Developer.

Giovanni Di Grezia