Operating Systems 2014F: Tutorial 1

From Soma-notes
Revision as of 12:00, 5 September 2014 by Soma (talk | contribs)
Jump to navigation Jump to search

In this lab you will be learning the basics of command-line interaction with UNIX/Linux. This lab should be completed in Tutorial.

Getting Started

For this lab, you need to get access to the class virtual machine or another Linux or UNIX machine. For more on how to access the virtual machine, see the Course Software page.

The Shell

The shell or command line provides a text interface for running programs. While not as visually pleasing as a graphical interface, the shell provides a more clear representation of the functionality provided by the operating system.

To run a program contained in the current directory in the shell, you need to prefix the name of the command with a ./. This "./" tells the shell that the location of the command you wish to run is the current directory. By default, the shell will not search for executable commands in the current working directory. To run most system commands, the name of the command can be typed without a path specification.

Help

  1. When working in the shell, help is available on most programs in the system, especially those that are command line based. This system of help is available by using the man command. If one wanted to get help on the echo command, the associated command would be man echo. What does man stand for?
  2. The man command can also be used to get help on standard C functions. Briefly (in one line), what does the C function brk do?
  3. How do you quit the less command?

Shell Basics

Note that csh is the default shell on the SCS systems. Other Linux distributions normally default to bash. Whenever there is a reference to csh in this document, you may substitute bash, zsh, or any other standard UNIX shell. Please, just be clear which shell you've chosen to use.

  1. The which command can be used to figure out what directory an executable program resides in. Using this command, what directory contains the top command?
  2. Which of the following is another shell that can be used instead of csh? mv, cat, bc, bash, or arch
  3. The ls command can be used to get a listing of the files in a directory. What options are passed to ls to see all of the files within a directory (including hidden files)?
  4. The ps command is used to get a list of processes which are running on the system. Start a new shell by typing "csh". Does the new shell replace or run in parallel with the old shell? What about exec csh? You can use the ps command to determine if the shell is still running.
  5. Because each process is started by some other process, there is a process tree structure on the system. From within your terminal, determine what process started csh by using the pstree command. What graphical application can give you the same information?

Processes

Each application running on a system is assigned a unique process identifier. The ps command shows the process identifiers for running processes. Each process running on the system is kept separated from other processes by the operating system. This information will be useful for subsequent questions.

Permissions

Your permission to access a file in Unix is determined by who you are logged in as. All files on the Unix file system (including directories and other special files) have three different sets of permissions. The first set of permissions denotes the allowed file operations for the owner of the file. The second set of permissions denotes the allowed file operations for a group of users. The third set of permissions denotes the allowed file operations for everyone else. A file is always owned by someone and is always associated with a group.

The ls command with the -l option can be used to show both the permissions of a file as well as the owner and group associated with the file. Permissions are listed first, followed by the owner and the group.

  1. Who is the owner of the /etc directory?
  2. What group is associated with the /etc/shadow file?
  3. Each user is a member of some number of groups. You can determine what groups you are part of by using the groups command. Based on the groups listed, would you be a member of the group associated with the /etc/shadow file?

Environment

The environment on both Linux and Windows contains variable - value pairs which are useful to applications running on the system. In Linux, these environment variables can be printed on the command line by referring to the variable name prefixed with a $ sign (eg: to output the value in the HELLO environment variable, one could write echo $HELLO).

  1. On the command line, run the following two sets of commands in the bash or csh shell. Notice that the shell command will start a new shell separate from the shell that the HELLO environment variable was set in.
HELLO="Hi There"          or       set HELLO="Hi There"
bash                               csh
echo $HELLO                        echo $HELLO
exit                               exit
export HELLO="Hi There"   or       setenv HELLO "Hi There"
bash                               csh
echo $HELLO                        echo $HELLO
exit                               exit

Note: Do not put spaces on either side of the equal signs!

What does the export command seem to do? (Or, what is the difference between set and setenv?)

Dynamic Libraries

Most applications on the system do not contain all the code that they need right within the executable. Instead, dynamic libraries are loaded into the program address space when the program loads. As an example, the standard C library, which contains such functions as printf is loaded in at run-time.

  1. Using ldd, what dynamic library dependencies does the top command have? Note that you must specify the full path to top.
  2. In addition to the libraries listed as dependencies for the application top by ldd, there may be other libraries that the application loads dynamically at run-time. Retrieve the process number PID for the csh process (using ps) and examine the map file located at /proc/PID/maps. What other dynamic libraries have been loaded into the application while it has been running?

Textbook Code

Try running the code covered in the Introduction of the textbook.