Dana Vrajitoru
C151 Multi-User Operating Systems

Lab 1

Due Date: Monday, February 1, 2021.

Ex. 1. File Manipulation

In this lab we will utilize some of the commands seen last week and introduce a set of new ones designed to handle processes. We will need two terminals for this task: the main one where most of the commands will be run from, and a second one where we will launch some processes. We will then find out information about these processes and manipulate them from the main terminal. You will need to copy the content of the main terminal to a simple text file called lab1.txt. See Lab 0 for instructions on how to copy the content of the terminal on any system.

Launch two terminals and connect them to the same Linux remote host using ssh, or simply open two terminals if you are working on a Linux system directly. Choose one of them to be your main.

To review the commands from the last week, in the main terminal change your working directory to the folder c151 that you created in Lab 0. Inside this folder, create another one called week1. Go to this directory. Copy the file time.h from /usr/include to this location. Rename this file as mytime.h (or copy it directly under this name). Edit the file with pico or gedit and add a comment with your name.

Suppose that you want to see all the files in /usr/bin that end in "cmd". The command for that would be

ls /usr/bin/*cmd

How about if you want to find all such files but you don't know which subdirectory of /usr to look into? You can use the following command for it:

find /usr -name "*cmd"

Can you see the difference between the results?

Now suppose you want to list a long list of attributes for these files. You'll have to feed the result of the previous command to the command "ls -l" as an argument. For this, use the up arrow key to go back to the command you just executed in the terminal. Use the Home button to go to the beginning of the line, and add

ls -l `

at the beginning. Note that the apostrophe after the -l option is not a usual single quote, but the one found at the top left corner of the keyboard bellow the Esc key. Go back to the end of the command using the End button, then close the apostrophe with the same character. Now hit Enter to execute the command.

Locate any system file with a name ending in gl.h using the commands locate (it takes the file name as argument) and then find (separately). For the command find, see the demo in the class lecture of this week.

Ex. 2. Processes, Jobs

Switch to the second terminal and type the command top. This will display the list of the most active processes on your computer. Note that the list updates frequently. Leave this application running, and switch back to the main terminal to continue with the rest of the lab. Find the processes running only in this main terminal with the command

ps

Why is the process for top not listed here? To see all the processes that are running on that computer, we need the option -A. Find out the process id number of the top process with the command

ps -Al

Kill this application (top) with the command

kill pid

where pid is the process ID number that you found in the previous command. Verify that it's not there anymore by taking a look at the second terminal. If the process has not been killed yet, then try the same command with an option that sends a stronger termination signal to the application:

kill -s 9 pid

Redo the ps command (still in the main terminal), but this time pipe it through the command less. This means that the result from the command ps will be forwarded as input to the command less, and thus, it will be viewed through the command less. For this, run the following command, where there is a vertical bar between the -Al and the command less, normally found on the back-slash key:

ps -Al | less

Scroll down in the list to find the first process with the parent process ID (5th column, PPID) being a number larger than 10. Write down its name and PID (process ID) number, then the parent ID (PPID). Look for the parent of this process (the process with a PID equal to the PPID of the first one) and write it down. Repeat the steps tracing it back until you get to process with the PID=1. You'll have to write the names and PIDs of these processes as text in the file lab1.txt containing the execution log of the lab.

Launch the application emacs from the terminal. You can type a few words if you want. Without closing the application, go back to the terminal by typing Ctrl-z. Make sure that emacs is still running by listing the active processes in the terminal. To go back to the emacs window, type the command

fg

Exit the emacs window with Ctrl-x Ctrl-c (keep the control down for both).

Canvas Submission

Make sure at this point that you copy everything from the main terminal (containing most of the commands) to the text file lab1.txt (see instructions at the top). Alternatively, if you have turned the Logging option on in Putty, simply rename the file putty.log as lab1.txt and move it to your class folder. Submit this file as your Lab 1 on Canvas under Assignments. The due date for this lab is Monday, February 1.