Lab 3 Linux Processes and Scripting

After completing the exercises in this lab, I became more comfortable with process management and scripting in a Linux environment. I am happy with the progress I made, and took time to develop my knowledge further by engaging with the suggested Bash tutorials.

Procedure

During this lab

  1. The lab3resources.zip file was downloaded to my local mahcine and uploaded to my DCS machine using scp ./lab3resources.zip u2014020@login-1.dcs.warwick.ac.uk:~/public_html/cs133/lab3.
  2. The cs133 directory was navigated to using cd public_html/cs133/lab3 on the server, the file was unzipped using unzip lab3resources.zip.
  3. nano runloop was used to create the specified script and permissions were changed using chmod 755 runloop to make the Bash script executable.
  4. ./runloop \& was used to run the program, which simply started an infinite loop.
  5. The ps command was used to find the process number, and then the memory and CPU usage of the process was examined using top -p {pid}. It was found the java process runloop spawned consumed no memory but 100 percent CPU.
  6. As the runloop file created a child process, java, it was necessary to kill them both. This was achieved using pkill -P {runloop_pid}. According to the pkill man page, this command will send a kill signal to each process which matches the provided name. Using pgrep may not be a useful way to kill a process as may unintentionally kill other processes which match the provided name.
  7. The sum script was created using nano, and the script specified in the lab. Permissions were adjusted using chmod. The three different references to sum involve initialising the value on the first line, assigning it the value of the three numbers added together on the second line and finally printing it out using string interpolation on the third line. When the script was adjusted to use four values, but only three were supplied, expr returned a syntax error.
  8. A script called mult was created using nano to multiply two numbers. Permissions were adjusted using chmod.
  9. Then, the sum script was extended to include a help message and accept any number of arguments. The for loop in the sum file goes through all the possible values passed as arguments and does not have a defined range or increment, like a Java loop. It is similar to a for-in loop over an array or ArrayList in Java. >\&2 is used to redirect output from the standard output stream to the standard error stream.
  10. The script pair was created using nano to sum pairs of numbers.
  11. Finally, a script called twosingledigits was created to fulfil Marking Point 3.3. Permissions were adjusted using chmod to make it executable and readable.

Commands

  • ps returns a snapshot of all the process running on the machine. The -e flag is used to list all processes on the machine.
  • pkill is used to kill a process based on name, and other specified attributes.
  • kill terminates a process by process number. Although the TERM signal, which can be caught by a process, is sent by default, the -9 flag can be used to force kill a process.