COMP 3000 Lab 1 2012: Difference between revisions

From Soma-notes
No edit summary
Line 3: Line 3:
For reference material, we suggest you look at this [http://linuxcommand.org/lc3_learning_the_shell.php tutorial on the shell] and the associated book [http://linuxcommand.org/tlcl.php The Linux Command Line] (available as a PDF for free and in print).  You may also use other Internet resources or other people. ''Please cite all sources that you use to answer the questions in this assignment.''
For reference material, we suggest you look at this [http://linuxcommand.org/lc3_learning_the_shell.php tutorial on the shell] and the associated book [http://linuxcommand.org/tlcl.php The Linux Command Line] (available as a PDF for free and in print).  You may also use other Internet resources or other people. ''Please cite all sources that you use to answer the questions in this assignment.''


You should turn in Lab 1 by 10 PM on Friday, September 21 via cuLearn.  Your answers should be in '''plain text''' (the true UNIX file format) or '''PDF'''.  No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format).
You should turn in Lab 1 by 10 PM on Friday, September 21 via cuLearn.  Your answers should be in '''plain text''' (the true UNIX file format) or '''PDF'''.  No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format).  Note the lab has 50 points in total.


You should expect to complete Part A in tutorial.  You should submit the answers to both Part A and Part B, however, on Friday.
You should expect to complete Part A in tutorial.  You should submit the answers to both Part A and Part B, however, on Friday.
You should use this as an opportunity to become familiar with the UNIX command line.  After this lab it will be assumed that you are reasonably fluent in basic shell usage.  If you do not feel so comfortable, you should study the above mentioned references.


==Part A==
==Part A==
Line 27: Line 29:
# [2] With the <tt>&amp;</tt> you can put processes in the "background".  Given that external commands are always run as separate processes from the command shell, what is the key difference between foreground and background processes?
# [2] With the <tt>&amp;</tt> you can put processes in the "background".  Given that external commands are always run as separate processes from the command shell, what is the key difference between foreground and background processes?
# [2] What are the differences between shell and environment variables?  Specifically, what processes have each of them, and to what extent are they shared?  HINT: look at the <tt>execve</tt> system call.
# [2] What are the differences between shell and environment variables?  Specifically, what processes have each of them, and to what extent are they shared?  HINT: look at the <tt>execve</tt> system call.
==Processes==
Each application running on a system is assigned a unique process identifier.  The <tt>ps</tt> 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 <tt>ls</tt> command with the <tt>-l</tt> 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.
# Who is the owner of the <tt>/etc</tt> directory? (1 point)
# What group is associated with the <tt>/etc/shadow</tt> file? (1 point)
# Each user is a member of some number of groups.  You can determine what groups you are part of by using the <tt>groups</tt> command. Based on the groups listed, would you be a member of the group associated with the <tt>/etc/shadow</tt> file? (1 point)
==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 <tt>echo $HELLO</tt>).
# On the command line, run the following two sets of commands in the <tt>bash</tt> or <tt>csh</tt> 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?) (2 points)
==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 <tt>printf</tt> is loaded in at run-time.
# Using <tt>ldd</tt>, what dynamic library dependencies does the <tt>top</tt> command have?  Note that you must specify the full path to <tt>top</tt>. (1 point)
# In addition to the libraries listed as dependencies for the application <tt>top</tt> by <tt>ldd</tt>, there may be other libraries that the application loads dynamically at run-time.  Retrieve the process number <em>PID</em> for the <tt>csh</tt> process (using <tt>ps</tt>) and examine the map file located at <tt>/proc/</tt><em>PID</em><tt>/maps</tt>.  What other dynamic libraries have been loaded into the application while it has been running? (2 points)
=Part B (take home)=
==Processes==
# What is the difference between the <tt>fork</tt> and <tt>exec</tt> function in a UNIX environment? ( 1 point )
# What is a zombie process? ( 1 point )
# Give an example C program which creates a zombie process.  Note that the shell by default will collect and destroy zombie processes and so you will need to avoid the shell destroying the zombie process during debugging.  This can be done by delaying the parent exit (using sleep is one good way to do this). ( 2 points )
# Perform the modifications to your program above to avoid creating a zombie process.  List the new program. ( 3 points )
==Permissions==
# Permissions on Unix are grouped into three basic file operations. What are these file operations? ( 1 point )
# What does it mean to have execute permission on a directory? ( 1 point )
# What are the 6 basic file permissions within Windows? ( 1 point )
# What is the difference between the write and modify file permission in Windows? ( 1 point )
# Because all files are stored in a directory, under UNIX permission to delete, rename, and move files is determined by the users access rights on the directory the file is contained in.  What attribute on the directory prevents those who can modify a directory from deleting files (hint: help on the <tt>chmod</tt> command may prove useful). ( 1 point )
# In Windows, a file can be associated with more than one group and each group can have different access permissions.  On Unix, each file can only belong to one group and groups cannot contain other groups (groups can only contain users).  Having said that, new groups can be created by the system administrator which are supersets of other groups (e.g., to create group C with members of A and B, just add all of A's and B's members to C).  Given this, is it possible to develop an access permission scenario which would be impossible to implement in Unix but possible to implement in Windows?  If yes, give an example.  If no, explain why. ( 1 point )
==Environment==
# What does the PATH environment variable do?  PWD? ( 1 point )
# What environment variable tells X applications where to find the X server which it should communicate with to display the output? ( 1 point )
==Dynamic Libraries==
Dynamic libraries allow one copy of executable code to be used by
many different processes on the system, without requiring that
multiple copies of the code be stored on disk in different files.
What are some problems that can arise when different programs use the
same common DLLs (hint: ``DLL Hell'')? ( 1 point )

Revision as of 14:49, 17 September 2012

In this lab you will be learning about the standard command shell on Linux, bash.

For reference material, we suggest you look at this tutorial on the shell and the associated book The Linux Command Line (available as a PDF for free and in print). You may also use other Internet resources or other people. Please cite all sources that you use to answer the questions in this assignment.

You should turn in Lab 1 by 10 PM on Friday, September 21 via cuLearn. Your answers should be in plain text (the true UNIX file format) or PDF. No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format). Note the lab has 50 points in total.

You should expect to complete Part A in tutorial. You should submit the answers to both Part A and Part B, however, on Friday.

You should use this as an opportunity to become familiar with the UNIX command line. After this lab it will be assumed that you are reasonably fluent in basic shell usage. If you do not feel so comfortable, you should study the above mentioned references.

Part A

  1. [10] What is your username on this wiki? Have a TA help you create an account.
  2. [1] What Linux distribution are you using? What version? You should look at the file /etc/issue generally to find out.
  3. [1] What shell do you get by default when you log in? Check by running echo $SHELL. If it is not bash, then type exec bash to switch to it.
  4. [1] Is your Linux environment running virtualized or on bare metal? How do you know? (If you aren't sure, say so, but explain why.)
  5. [1] Who installed and configured your Linux environment? What level of access do you have to it?
  6. [2] A shell command can be one of four things. What are those four things? Explain very briefly.
  7. [2] On the machine you are on, in what directories are commands external to the shell stored? How can you get this information on the command line?
  8. [2] Compare the commands ls /usr/bin | more and ls /usr/bin | less. How is the output similar? How are they different?

Part B

  1. [4] Some shell commands, such as pwd, are both built-in and are external. What is one reason why both versions might be present?
  2. [4] What are the permissions on your Linux home directory? With those permissions and your knowledge of the other accounts on the system, who has access to your home directory, and what sort of access do they have?
  3. [10] Give one or more command line strings that use the following operators: >, <, >>, <<, |. Explain briefly what each operator is doing in your examples, both concretely and in terms of STDIN and STDOUT.
  4. [2] Are there operators that work specifically with STDERR? Explain briefly.
  5. [2] How do you use these operators with other file descriptors? Explain briefly.
  6. [2] Give an example of a bash for loop and explain what it does.
  7. [2] Give an example of a bash if statement and explain what it does.
  8. [2] With the & you can put processes in the "background". Given that external commands are always run as separate processes from the command shell, what is the key difference between foreground and background processes?
  9. [2] What are the differences between shell and environment variables? Specifically, what processes have each of them, and to what extent are they shared? HINT: look at the execve system call.