please explain below The whole line of code in the Shell script that starts with if, have you seen the application scenario ?
if (kill-0 $pid 2>/dev/du11) then echo "Oldboy" Else echo "Oldgirl" fi
Interview question: Please explain the meaning of if (kill-0 $pid 2>/dev/null) code?
if (kill-0 $pid 2>/dev/null) then echo "Oldboy" Else echo "Oldgirl" fi
The old boy answers the main points:
kill-0 $pid 0 means not to send any signal to the PID corresponding process, but still the variable value PID corresponding to the existence of the process check, if the $pid corresponding process exists, then returns 0, does not exist return 1.
2>/dev/null does not output error messages.
The application scenario in the system is a script snippet that stops the MySQL service in MySQL's/etc/init.d/mysqld script.
Use the/etc/init.d/mysqld Stop command to execute a script to close the database with the following program code:
'stop')
# Stop Daemon. We USEA signal here to avoid have to know the
# root password.
iftest - S " $mysqld _pid_file_path "
Then
mysqld_pid=' cat '$mysqld _pid_file_path"'
off (kill-0$mysqld _pid2>/dev/null)
Then
Echo $echo _n " shutting down MySQL "
Kill $mysqld _pid
# mysqld Shouldremove The PID file when it exits, so wait for it.
Wait_for_pid removed "$mysqld _pid" "$mysqld _pid_file_path" ; Return_value=$?
Else
Log_failure_msg "MySQL Server process #$mysqld _pidis notrunning! "
RM " $mysqld _pid_file_path "
fi
# Delete Lock Forredhat/suse
if test - F " $lock _file_path "
Then
RM - F " $lock _file_path "
fi
Exit $return _value
Else
Log_failure_msg "mysqlserver PID file could not be found! "
Fi
;;
This article is from the "Long Wing blog" blog, please be sure to keep this source http://youjiu.blog.51cto.com/3388056/1911141
Old boy Education Day: March 9, 2017-please explain the meaning of the entire line of code in the shell script below and the application scenario?