1) COMMAND="$CMD -p $PORT -l $LISTEN_IP -m $MEM_SIZE -v" - -v in the Unix tradition, it is often a shortcut for --verbose . All these dollar signs are variable extensions (their text values ββare inserted into the string assigned to the new COMMAND variable).
2) ps -ef | grep -v grep | grep $( cat $PID ) ps -ef | grep -v grep | grep $( cat $PID ) ps -ef | grep -v grep | grep $( cat $PID ) is pipe: ps redirects its output to grep, which outputs to another grep, and the final result is printed to standard output. grep -v grep means "accept all lines that do not contain" grep "(grep itself is a process, so you need to exclude it from ps output). $( $command ) is a way to run a command and paste its standard output into it the location of the script (in this case: cat $PID displays the contents of a file named $ PID).
3) kill_cmd . This function is an endless loop trying to kill the LIST of memcached PID modules. Firstly, he tries to send a TERM signal (politely asking each process in $ LIST to exit, save his work and close it correctly), gives them 2 seconds ( sleep 2 ) to complete the job, and then he tries to make sure that all processes are destroyed using the KILL signal ( -9 ), which immediately terminates the process using the capabilities of the OS: if the process has not completed operation within 2 seconds, it is considered to be freezing). If slaying with kill -9 was successful, it deletes the PID file and terminates the loop.
ps -ef | grep -v grep | grep $CMD | grep -w $USR | awk '{print $2}' ps -ef | grep -v grep | grep $CMD | grep -w $USR | awk '{print $2}' prints all PIDs of processes with the name $ CMD ('memcached') and the user $ USR ('user'). -w option grep means "full word only" (this excludes situations when the searched name is part of another process name, for example "fakememcached"). awk is a small interpreter that is most often used to enter the word number N from each input line (you can think of it as a selector for a text table column). In this case, it prints every second word in ps output lines, which means every PID.
If you have other questions, I will add the answers below.
source share