1. Master the basic method of writing Linux shell script 2. Have a deeper understanding of processes by writing Linux shell scripts. Experiment Content [Basic Requirements] This section describes how to write a shell script. The function of this script is to input a number, give details about the pid process in the system, and output the details to a file. When executing a script, take a number as an input. Have basic comments
3. Experimental Report (1) Requirement 1: $pid/exe -l /proc/$pid/exe -l /proc/$pid/exe -l /proc/$pid/exe -l /proc/$pid/exe -l /proc/$pid/exe If you don’t get the PID of the process procedures, the number the command will be an error, this time with the eq 0] [$? – judgment test, returns 0 if successful, the rest are required by 3: fail to provide the corresponding menu allows the user to input process, and decide whether to terminate the process requirement 4: add a function: Ps-aux can input all the current process information, but we do not know which process the user needs to see, so we can use awk command to intercept the first line, and then according to the PID input of the user to find the corresponding line results and output in shell language. Kill -9 $pid helps us to terminate the process directly
(4) [Important] Problems encountered in the experiment and solutions 1. The corresponding PID information cannot be displayed: Read -p pid = echo -p pid = echo -p pid = echo -p pid = echo -n 2. If statement cannot be executed, or sh test.sh often says else near syntax error [line 24: Syntax error near unexpected token ‘fi’] the problem is that my text compilation environment is Windows environment with notepad++, in the hidden symbol, Windows newline is CF LF, while Unix environment is LF, Problem solved after switching text environment. 3. Some PID can not be killed, but there is no corresponding information display, preliminary judgment is because there is no corresponding permission, so even view the situation are not allowed to have it…