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?

Source: Internet
Author: User

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:

  1. 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. 2>/dev/null does not output error messages.

  3. The application scenario in the system is a script snippet that stops the MySQL service in MySQL's/etc/init.d/mysqld script.

  4. 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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.