メモ:シグナル

シグナルを処理するだけの簡単なサンプルをc/node.js/pythonで。

#include <unistd.h>
#include <string.h>

static void
func(){
    write(2,"SIGINT\n",7);
}

int 
main(void){
    struct sigaction act;
    //struct sigaction act2;
    memset(&act,0,sizeof act );
    act.sa_handler = func;
    if( sigaction(SIGINT ,&act,NULL) < 0){
        perror("syserror");
        return 1;
    }
    sleep(60);
    return 0;
}
import signal
import time

def func(signam,stack):
    print signam
    exit(1)


signal.signal(signal.SIGINT,func)


time.sleep(60)
process.on('SIGINT',function(){
    console.log("SIGINT");
    process.exit(1);
});

setTimeout(function(){
    process.exit(0);
},60*1000);