BerandaComputers and TechnologyYou Should Feel Guilty For Killing -9 Your Linux Processes

You Should Feel Guilty For Killing -9 Your Linux Processes

Every day, Linux users misuse the kill utility when trying to terminate a process. You go and type the famous kill -9, and all the problems are solved. But should you do that?

kill is a shell builtin in most Bourne-derived shells such as Bash and Zsh.

KILL(1)NAMEkill — terminate or signal a processSYNOPSISkill [-s signal_name] pid …kill -l [exit_status]kill -signal_name pid …kill -signal_number pid …DESCRIPTIONThe kill utility sends a signal to the processes specified by the pid operands.Only the super-user may send signals to other users’ processes.

It doesn’t give the process a chance to cleanly. Your process may need to:

  • Shut down socket connections
  • Clean up temp files
  • Inform its children that it is going away
  • Reset its terminal characteristics

There are many other cleanup cases.

Let’s look at the available options.

0 - ? 

1 - SIGHUP - ?, controlling terminal closed,

2 - SIGINT - interupt process stream, ctrl-C

3 - SIGQUIT - like ctrl-C but with a core dump, interuption by error in code, ctl-/

4 - SIGILL

5 - SIGTRAP

6 - SIGABRT

7 - SIGBUS

8 - SIGFPE

9 - SIGKILL - terminate immediately/hard kill, use when 15 doesn't work or when something disasterous might happen if process is allowed to cont., kill -9

10 - SIGUSR1

11 - SIGEGV

12 - SIGUSR2

13 - SIGPIPE

14 - SIGALRM

15 - SIGTERM - terminate whenever/soft kill, typically sends SIGHUP as well?

16 - SIGSTKFLT

17 - SIGCHLD

18 - SIGCONT - Resume process, ctrl-Z (2nd)

19 - SIGSTOP - Pause the process / free command line, ctrl-Z (1st)

20 - SIGTSTP

21 - SIGTTIN

22 - SIGTTOU

23 - SIGURG

24 - SIGXCPU

25 - SIGXFSZ

26 - SIGVTALRM

27 - SIGPROF

28 - SIGWINCH

29 - SIGIO

29 - SIGPOLL

30 - SIGPWR - shutdown, typically from unusual hardware failure

31 - SIGSYS

You got some options, my friend! To kill a process respectfully, you should:

  • Try to send a SIGTERM by using kill -15.
  • After a few seconds, If It is not dead send a SIGINT .
  • If It persists send a SIGHUP .

What if it doesn’t want to terminate at the end?

  • If you are using an external binary and it didn’t stop after all of this, you should probably get rid of it.
  • If you are developing a program and can’t get it to stop correctly, you should better handle the killing signals.

Just don’t use kill -9.

Read More

Berita sebelumyaSegment: The Yin to Twilio’s Yang
Berita berikutnyaThis And That
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments