Friday, 5 August 2016

What is the usage of -9 in kill command ?


There are many switches other than 9 and can be used with kill command.
  • SIGHUP (hangup)
    Tells the program that the user disconnected (e.g. SSH session or terminal window was closed)
    Usually does a graceful shutdown of the program.
  • SIGINT (interrupt)
    Sent when you hit CTRL+C
    Usually means "stop what you're doing" - may or may not kill the program
  • SIGTERM (terminate)
    The default sent by kill and killall.
    Usually terminates the program... sometimes after the program finishes whatever it's doing.
  • SIGSTOP (stop)
    Sent when you hit CTRL+Z
    Pauses the program, discussed above
  • SIGPIPE (pipe closed)
    Tells the program that the the pipeline has closed.
    Usually terminates the program.
    For example cat /etc/passwd | head -n1 will send SIGPIPE to the cat process after the first line is printed, causing cat to terminate before finishing the whole file.
     

How to add 2 numbers in shell script ?


Use $(expr ..) or $((..))

sum = $(expr "$num1" + "$num2")
echo $sum
OR

sum = $((num1 + num2)) 
echo $sum 

Following are incorrect commands :
echo $num1 + $num2;
echo `$num1` + `$num2`;