Results 1 to 5 of 5

Thread: SIGKILL vs SIGINT

  1. #1
    Join Date
    Aug 2012
    Beans
    623

    SIGKILL vs SIGINT

    Hello,
    I googled up a bit and I'm aware that SIGKILL is ungraceful termination(signal #9) whereas SIGINT is on pressing the Ctrl+c and is not killing, but only interruption.

    But, what I find hard to understand is, even after doing a Ctrl+c, when I do a $ps, I don't see that process. Since it is only interrupted and not killed, shouldn't it still show up is the ps output.

    I'm not able to figure out what SIGINT does.

    Thanks.
    Last edited by IAMTubby; September 30th, 2012 at 07:13 PM.

  2. #2
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,499
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: SIGKILL vs SIGINT

    depends on what the process does with that SIGINT, usually it means exit.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  3. #3
    Join Date
    Mar 2007
    Location
    Turkey
    Beans
    1,574

    Re: SIGKILL vs SIGINT

    It is the same as sending CTRL-C. Try it in the terminal.

  4. #4

    Re: SIGKILL vs SIGINT

    SIGINT can be caught and handled. It's like telling the process "Please stop what you're doing." The process is free to ignore the signal, or implement a handler that does anything it wants. The default behavior is to terminate, and this is what most processes will do. It's typical, but not required, for a process to handle SIGINT by gracefully terminating -- closing any open files, network connections, or database handles and stopping the current operation in such a way that prevents data loss or corruption.

    SIGKILL can't be handled by the receiving process. If a process gets sent SIGKILL, it's toast, period. If a process receives SIGKILL in the middle of a database transaction or file write (for instance), it has no chance to exit gracefully and data loss or corruption may occur.

    When you do Ctrl-C in the terminal, the terminal sends SIGINT to the running process. Like I said before, most processes will gracefully terminate on receiving SIGINT. Once it's terminated, it's just as surely ended as if it had been SIGKILL'ed or exited normally -- you shouldn't expect to see it in ps because it's still gone.

    But there are some programs that don't respond to SIGINT in that way. bash is one example; if you hit Ctrl-C at a shell prompt, it'll just cancel whatever you've typed on that line -- not terminate the whole shell. Again, this is because the behavior when a process receives SIGINT is determined by the process itself. vi is another program that doesn't handle SIGINT by terminating.

  5. #5
    Join Date
    Sep 2006
    Beans
    8,627
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: SIGKILL vs SIGINT

    SIGINT and others can be caught and handled. You can try running the perl script below in one terminal and in another sending various signals to it using kill or pkill. Or in the same terminal you could press ctrl-C to send SIGINT.

    Code:
    #!/usr/bin/perl
    
    use sigtrap qw(die QUIT);
    
    sub trap_int {
     print qq(Ouch\n);
     exit ( 0 );
    }
    
    sub trap_hup {
     print qq(Hang up\n);
    }
    
    $SIG{INT} = \&trap_int;
    $SIG{HUP} = \&trap_hup;
    
    while (1) {
      print qq(Doing something for 500 seconds\n);
      sleep( 500 );
      print qq(Continuing\n);
    }
    Some programs will, for example, reload the configuration file when receiving a SIGHUP. But what the program actually does upon receiving a signal is up to the designer.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •