<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zliu10</id>
	<title>Soma-notes - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Zliu10"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/Zliu10"/>
	<updated>2026-05-04T10:10:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2402</id>
		<title>COMP 3000 Lab 2 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2402"/>
		<updated>2010-10-06T17:18:11Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Help */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following lab requires access to a relatively standard Linux environment.  Use a virtual machine version of Ubuntu or log in to one of the SCS Linux machines.  Alternately, use your own Linux installation (installed natively or in a virtual machine).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note - this lab is not yet finalized!&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Part A (Mandatory)=&lt;br /&gt;
&lt;br /&gt;
==The Shell==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To run a program contained in the current directory in the shell, you need to prefix the name of the command with a &amp;lt;tt&amp;gt;./&amp;lt;/tt&amp;gt;.  This &amp;quot;./&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
===Help===&lt;br /&gt;
&lt;br /&gt;
#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 &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command.  If one wanted to get help on the echo command, the associated command would be &amp;lt;tt&amp;gt;man echo&amp;lt;/tt&amp;gt;.  What does &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; stand for?&lt;br /&gt;
#The &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command can also be used to get help on standard C functions.  Briefly (in one line), what does the C function &amp;lt;tt&amp;gt;brk&amp;lt;/tt&amp;gt; do?&lt;br /&gt;
# How do you quit the &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
&lt;br /&gt;
===Shell Basics===&lt;br /&gt;
&lt;br /&gt;
# The &amp;lt;tt&amp;gt;which&amp;lt;/tt&amp;gt; command can be used to figure out what directory an executable program resides in.  Using this command, what directory contains the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
# &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; is your default shell.  Which of the following is another shell that can be used instead of BASH?&amp;lt;tt&amp;gt; mv, cat, bc, tcsh, or arch &amp;lt;/tt&amp;gt;&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command can be used to get a listing of the files in a directory.  What options are passed to &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; to see all of the files within a directory (including hidden files)?&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command is used to get a list of processes which are running on the system.  Start a new shell from bash by running &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt;.  Does the new shell replace or run in parallel with the old BASH shell?  What about &amp;lt;tt&amp;gt;exec bash&amp;lt;/tt&amp;gt;?  You can use the &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command to determine if bash is still running.&lt;br /&gt;
# Because each process is started by some other process, there is a process tree structure on the system.  From within your bash terminal, determine what process started BASH by using the &amp;lt;tt&amp;gt;pstree&amp;lt;/tt&amp;gt; command.  What graphical application can give you the same information?&lt;br /&gt;
/usr/bin/top&lt;br /&gt;
tcsh&lt;br /&gt;
ls -a&lt;br /&gt;
bash: open a new one.&lt;br /&gt;
exec bash: replace the old one&lt;br /&gt;
init--gnome-terminal--bash&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
Each application running on a system is assigned a unique process identifier.  The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
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 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&lt;br /&gt;
file is always owned by someone and is always associated with a group.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command with the &amp;lt;tt&amp;gt;-l&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
#Who is the owner of the &amp;lt;tt&amp;gt;/etc&amp;lt;/tt&amp;gt; directory?&lt;br /&gt;
A: root&lt;br /&gt;
# What group is associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: shadow&lt;br /&gt;
# Each user is a member of some number of groups.  You can determine what groups you are part of by using the &amp;lt;tt&amp;gt;groups&amp;lt;/tt&amp;gt; command. Based on the groups listed, would you (the ``student&#039;&#039; user in the lab) be a member of the group associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: no&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;echo $HELLO&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
# On the command line, run the following two sets of commands.  Notice that the bash command will start a new shell separate from the shell that the HELLO environment variable was set in.&lt;br /&gt;
&lt;br /&gt;
 HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
 export HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
What does the export command seem to do?&lt;br /&gt;
declare a global variable&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;printf&amp;lt;/tt&amp;gt; is loaded in at run-time.&lt;br /&gt;
&lt;br /&gt;
# Using &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, what dynamic library dependencies does the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command have?&lt;br /&gt;
# In addition to the libraries listed as dependencies for the application &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, there may be other libraries that the application loads dynamically at run-time.  Retrieve the process number &amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt; for the &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; process (using &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) and examine the map file located at &amp;lt;tt&amp;gt;/proc/&amp;lt;/tt&amp;gt;&amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt;&amp;lt;tt&amp;gt;/maps&amp;lt;/tt&amp;gt;.  What other dynamic libraries have been loaded into the application while it has been running?&lt;br /&gt;
&lt;br /&gt;
Linux-gate.so.1, libproc, libncurses, libc, libdl, /lib/ld-linux&lt;br /&gt;
&lt;br /&gt;
=Part B (Optional)=&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; function in a UNIX environment?&lt;br /&gt;
# What is a zombie process?&lt;br /&gt;
# Give an example C program which creates a zombie process.  Note that &amp;lt;tt&amp;gt;BASH&amp;lt;/tt&amp;gt; by default will collect and destroy zombie processes and so you will need to avoid bash destroying the zombie process during debugging.  This can be done by delaying the parent exit (using sleep is one good way to do this).&lt;br /&gt;
# Perform the modifications to your program above to avoid creating a zombie process.  List the new program.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
# Permissions on Unix are grouped into three basic file operations. What are these file operations?&lt;br /&gt;
# What does it mean to have execute permission on a directory?&lt;br /&gt;
# What are the 6 basic file permissions within Windows?&lt;br /&gt;
# What is the difference between the write and modify file permission in Windows?&lt;br /&gt;
# 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 &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command may prove useful).&lt;br /&gt;
# In Windows, a file can be associated with more than one group and each group can have different access permissions.  On Unix, new groups can be created by the system administrator which are supersets of other groups.  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.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
# What does the PATH environment variable do?&lt;br /&gt;
# What environment variable tells X applications where to find the X server which it should communicate with to display the output?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
Dynamic libraries allow one copy of executable code to be used by&lt;br /&gt;
many different processes on the system, without requiring that&lt;br /&gt;
multiple copies of the code be stored on disk in different files.&lt;br /&gt;
What are some problems that can arise when different programs use the&lt;br /&gt;
same common DLLs (hint: ``DLL Hell&#039;&#039;)?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_1_2010&amp;diff=2401</id>
		<title>COMP 3000 Lab 1 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_1_2010&amp;diff=2401"/>
		<updated>2010-10-06T17:17:11Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Part A (Mandatory) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
# Create a virtual machine in VirtualBox for Ubuntu Linux and install Ubuntu using the ISO image in C:\support\somayaji.&lt;br /&gt;
#*Create your disk image on your Desktop or on a USB stick.&lt;br /&gt;
#*Images on your desktop will be deleted when you log out; USB stick images will be slower to access.&lt;br /&gt;
#*USB sticks may need to be formatted with NTFS to support a VirtualBox image. &lt;br /&gt;
#*Create a fixed-sized disk to increase performance.  However, you&#039;ll then have to wait for the fixed-sized disk to be allocated.&lt;br /&gt;
#*If you wish, you can use the Ubuntu install ISO as a live CD image.  In this case you don&#039;t need to install to any virtual hard disks.&lt;br /&gt;
#Create an account on the class wiki.  If you choose not to use your connect username please email me with your real name and your wiki username.&lt;br /&gt;
# Install the guest additions to your Ubuntu guest.  What new capabilities do you get?&lt;br /&gt;
#*To install, first mount the guest additions ISO using the &amp;quot;Devices&amp;quot; VirtualBox menu option.&lt;br /&gt;
#*To run the additions script, start up a Terminal window and run &amp;quot;sudo sh /media/&amp;lt;VBOXADD...&amp;gt;/VBoxLinuxAdditions-x86.run&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
# How much RAM does the VM use on the host?  How much is available in the VM?&lt;br /&gt;
# Look at the Disk Utility application in Ubuntu.  What sort of storage hardware does it have?  How does this compare to the hardware on the Windows host?&lt;br /&gt;
CD Drive and hard Disk. Hard disk is 8.6GB. We assign 8G as fixed size disk, why it shows 8.6G in Disk Utility?&lt;br /&gt;
# Look at /proc/cpuinfo in the Ubuntu guest - is the CPU the same as that reported by Windows?&lt;br /&gt;
&lt;br /&gt;
# What about the PCI devices as reported by the command line program &amp;quot;lspci&amp;quot;?&lt;br /&gt;
Guest OS can use all the PCI devices as the host can use.&lt;br /&gt;
# How does the performance of the VM compare to that of the host OS?  Examine GUI, disk, and network performance.&lt;br /&gt;
Feel free to add your tips for the above exercises here.&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
#Run benchmarks in the guest and host OSs such as lmbench for Linux.&lt;br /&gt;
#*Tip: phoronix-test-suite, rambench, cpuburn, bashmark, forkbomb&lt;br /&gt;
#Enable support for flash and non-free codecs in Ubuntu.&lt;br /&gt;
#Create an Ubuntu virtual machine in VMWare Player.  How does the performance of VMWare and VirtualBox compare?&lt;br /&gt;
#Can you run VirtualBox in the Ubuntu guest?  Note that VirtualBox is part of the Ubuntu distribution already.&lt;br /&gt;
# Setup shared folders between the guest and host and verify that you can copy files both ways.  What does the shared folder look like to Ubuntu?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2352</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2352"/>
		<updated>2010-10-05T15:20:53Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Fork &amp;amp; Exec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Note: The file names may have been switched. Try using the wait-signal1.c for part 2 and wait-signal.c for part 3 - --[[User:AbsMechanik|AbsMechanik]] 15:11, 5 October 2010 (UTC)&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2349</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2349"/>
		<updated>2010-10-05T15:20:05Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* IPC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
A: The two programs run paralle. Scheduling. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
A: When we run the maker_func(),we meet sleep(1). The the CPU jump to printer_func().&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
with fork(), you get a new process. and you can use exec( ) to replace the parent process by the child process.&lt;br /&gt;
with clone(), you get a new thread, it shares some property with the process. and you can not replace the process by this thread.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Note: The file names may have been switched. Try using the wait-signal1.c for part 2 and wait-signal.c for part 3 - --[[User:AbsMechanik|AbsMechanik]] 15:11, 5 October 2010 (UTC)&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2348</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2348"/>
		<updated>2010-10-05T15:17:33Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Processes and Threads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
A: The two programs run paralle. Scheduling. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
A: When we run the maker_func(),we meet sleep(1). The the CPU jump to printer_func().&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
with fork(), you get a new process. and you can use exec( ) to replace the parent process by the child process.&lt;br /&gt;
with clone(), you get a new thread, it shares some property with the process. and you can not replace the process by this thread.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
Note: The file names may have been switched. Try using the wait-signal1.c for part 2 and wait-signal.c for part 3 - --[[User:AbsMechanik|AbsMechanik]] 15:11, 5 October 2010 (UTC)&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
1. &lt;br /&gt;
  1. TERM&lt;br /&gt;
  2. 	signal(SIGCHLD, child_handler); and the definition of child_hander (only one arguments)&lt;br /&gt;
3&lt;br /&gt;
1. the third: shmflg&lt;br /&gt;
2. user can read+write+execute; group can read+write, others cannot do anyting.&lt;br /&gt;
3. 0600&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2344</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2344"/>
		<updated>2010-10-05T14:48:02Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Fork &amp;amp; Exec */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
2. The printer_func keeps checking the buffer, before it could get arg, it will never quit automatically. the only chance for maker_func to run is, when printer_func runs out of its quantum, and CPU is scheduled to maker_func. It is a waste of time. A better method of waiting is sleep for 1ms, then check.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
with fork(), you get a new process. and you can use exec( ) to replace the parent process by the child process.&lt;br /&gt;
with clone(), you get a new thread, it shares some property with the process. and you can not replace the process by this thread.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
1. &lt;br /&gt;
  1. TERM&lt;br /&gt;
  2. 	signal(SIGCHLD, child_handler); and the definition of child_hander (only one arguments)&lt;br /&gt;
3&lt;br /&gt;
1. the third: shmflg&lt;br /&gt;
2. user can read+write+execute; group can read+write, others cannot do anyting.&lt;br /&gt;
3. 0600&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2343</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2343"/>
		<updated>2010-10-05T14:44:52Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Processes and Threads */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
2. The printer_func keeps checking the buffer, before it could get arg, it will never quit automatically. the only chance for maker_func to run is, when printer_func runs out of its quantum, and CPU is scheduled to maker_func. It is a waste of time. A better method of waiting is sleep for 1ms, then check.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
1. &lt;br /&gt;
  1. TERM&lt;br /&gt;
  2. 	signal(SIGCHLD, child_handler); and the definition of child_hander (only one arguments)&lt;br /&gt;
3&lt;br /&gt;
1. the third: shmflg&lt;br /&gt;
2. user can read+write+execute; group can read+write, others cannot do anyting.&lt;br /&gt;
3. 0600&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2335</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2335"/>
		<updated>2010-10-05T04:48:26Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* IPC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
1. &lt;br /&gt;
  1. TERM&lt;br /&gt;
  2. 	signal(SIGCHLD, child_handler); and the definition of child_hander (only one arguments)&lt;br /&gt;
3&lt;br /&gt;
1. the third: shmflg&lt;br /&gt;
2. user can read+write+execute; group can read+write, others cannot do anyting.&lt;br /&gt;
3. 0600&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2334</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2334"/>
		<updated>2010-10-05T04:14:33Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* IPC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
1. &lt;br /&gt;
  1. TERM&lt;br /&gt;
  2. 	signal(SIGCHLD, child_handler); and the definition of child_hander (only one arguments)&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2333</id>
		<title>COMP 3000 Lab 3 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_3_2010&amp;diff=2333"/>
		<updated>2010-10-05T04:06:47Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* IPC */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Please answer all questions below. &lt;br /&gt;
&lt;br /&gt;
Part A is designed to be done in the lab while part B is designed to be done on your own time. Many of the questions require you to compile and run sample programs. These programs can be compiled using either the virtual machine environment you created, your own Linux installation, or your SCS Linux account.&lt;br /&gt;
&lt;br /&gt;
For all questions asking you to modify source code, you should always start with a clean version of the source code and modify that (unless otherwise directed in the question). Don’t continue modifying your solution to a previous question in order to answer the next question.&lt;br /&gt;
&lt;br /&gt;
All programs given in this assignment are written in C. A makefile is provided to compile the core programs given by the assignment—type “make” to compile. If you wish to rename files, you will need to either edit the makefile or run GCC to compile the programs on your own.&lt;br /&gt;
&lt;br /&gt;
All files are available [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/ here] individually; a ZIP archive is [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3.zip here].&lt;br /&gt;
&lt;br /&gt;
==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
===Processes and Threads===&lt;br /&gt;
&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/threads.c threads.c] is a multithreaded producer/consumer program. Unfortunately it consumes faster than it produces, resulting in an error. Why does it not print the same number every time?&lt;br /&gt;
# The program [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/passstr.c passstr.c] is a multithreaded program using the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; function call. What is wrong with the way this program blocks, waiting for the string to arrive in the buffer?&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;clone&amp;lt;/tt&amp;gt; and the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; function call?&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
&lt;br /&gt;
Examine the program given in [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c]. It multiplies two matrices together using the standard trivial algorithm (which also happens to be a n3 algorithm). It spawns off a child process to compute the value of each element in the resulting matrix. The program has a problem, however, in that it fails to pass the resulting values back to the parent process in order to give the right result. In this section, we will examine various methods for passing data between processes.&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Signals can be sent to each process running on the system. Signals, however, don’t allow the passing of any data along with the signal. Therefore, they are most useful for triggering actions.&amp;lt;br /&amp;gt;&lt;br /&gt;
## The &amp;lt;tt&amp;gt;kill&amp;lt;/tt&amp;gt; command actually sends signals to processes. What signal does the kill command by default send to a process?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] file to use the signal function to install the signal handler instead of the sigaction function call. You can have it install the child handler alt signal handler instead of the child handler signal handler. What line did you add to install the signal handler to child handler alt?&lt;br /&gt;
## Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal-1.c wait-signal-1.c] file to ignore the abort signal. What line did you have to add to do this?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Pipes (also called FIFO’s) allow two processes to communicate through a file handle. One process writes data into a file handle and the other process can then read that data out through a related but different file handle.&lt;br /&gt;
## What happens to file descriptors across an &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; call? Write a small program that tests this behavior, i.e. that opens a file, calls execve, and then the new program attempts to read from the previously opened file descriptor. Explain how this program behaves.&lt;br /&gt;
## Compile and run [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/pipe.c pipe.c]. Notice how data is sent through the pipe by writing to one end of the pipe in the child and reading from the other end of the pipe in the parent. Also notice how the message Finished writing the data! is never displayed on the screen. The problem has to do with the SIGPIPE signal. What is the problem?&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&lt;br /&gt;
## Shared memory regions are controlled by the kernel to prevent other processes from accessing the memory without permission. Like files in Unix, the shared memory regions are given read, write and execute permission. These permissions are specified in the call to shmget. Where in the arguments to shmget are the permissions specified?&lt;br /&gt;
## The permissions must be specified as a value. By reading the manpage of chmod, determine what the permission 0760 means.&lt;br /&gt;
## What number is going to be required in order for two processes owned by the same user to be able to read and write to the shared memory?&lt;br /&gt;
1. TERM&lt;br /&gt;
2.&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
===Processes===&lt;br /&gt;
#From class, you know that the process descriptor contains numerous information about a running process on the system. The task structure in Linux is called struct task struct. By examining the source of the Linux kernel, determine what source file this structure is defined in. The grep command may be useful in locating the correct file.&lt;br /&gt;
# Figure 6.3 (page 213) in your textbook contains a list of common elements found in a process table. Determine at least one variable in the Linux task structure which is related to each element listed in Figure 6.3. You may omit address space and stack.&lt;br /&gt;
&lt;br /&gt;
===Fork &amp;amp; Exec===&lt;br /&gt;
# Examining the flags that can be passed to the clone function call. Choose 5 flags and describe a situation in which each of them would be useful.&amp;lt;br /&amp;gt;Find the portion of the Linux kernel that implements the fork, clone, and vfork system calls for i386 systems. Based upon this code, could Linux instead just have one of these system calls?&amp;lt;br /&amp;gt; If so, which one, and how would you implement userspace “wrappers” that would provide identical functionality for the other two calls?&amp;lt;br /&amp;gt;If not, why are all three necessary? Explain.(For this question, ignore issues of binary compatibility.)&lt;br /&gt;
# File descriptors 0, 1, and 2 are special in Linux, in that they refer to standard in, standard out, and standard error. Does the Linux kernel know they are special? Explain, referring to appropriate parts of the Linux kernel source.&lt;br /&gt;
&lt;br /&gt;
===IPC===&lt;br /&gt;
In this section, you will be modifying the program wait-signal to correctly compute the value of the matrix multiplication.&lt;br /&gt;
# &amp;lt;b&amp;gt;Signals&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Describe in words how you might modify the wait-signal program to correctly pass back the value computed in the child to the parent using only signals. Remember that signals do not allow data to be passed back and forth. Also keep in mind that there are only around 32 signals that can be sent to a process. You do not have to implement your answer, only describe what you would do.&lt;br /&gt;
# &amp;lt;b&amp;gt;Pipes&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify the [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] program to pass the appropriate matrix data back to the parent via a pipe. Remember that you will also have to pass back the x and y locations that the data should be put in. What is your updated main function?&lt;br /&gt;
# &amp;lt;b&amp;gt;Shared Memory&amp;lt;/b&amp;gt;&amp;lt;br /&amp;gt;Modify [http://homeostasis.scs.carleton.ca/~soma/os-2010f/lab3/wait-signal.c wait-signal.c] to send data back to the main process using shared memory. You will need to use the functions shmget and shmat.&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2272</id>
		<title>COMP 3000 Lab 2 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2272"/>
		<updated>2010-09-28T15:25:30Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Dynamic Libraries */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following lab requires access to a relatively standard Linux environment.  Use a virtual machine version of Ubuntu or log in to one of the SCS Linux machines.  Alternately, use your own Linux installation (installed natively or in a virtual machine).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note - this lab is not yet finalized!&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Part A (Mandatory)=&lt;br /&gt;
&lt;br /&gt;
==The Shell==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To run a program contained in the current directory in the shell, you need to prefix the name of the command with a &amp;lt;tt&amp;gt;./&amp;lt;/tt&amp;gt;.  This &amp;quot;./&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
===Help===&lt;br /&gt;
&lt;br /&gt;
#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 &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command.  If one wanted to get help on the echo command, the associated command would be &amp;lt;tt&amp;gt;man echo&amp;lt;/tt&amp;gt;.  What does &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; stand for?&lt;br /&gt;
A: echo deisplys a line of text&lt;br /&gt;
#The &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command can also be used to get help on standard C functions.  Briefly (in one line), what does the C function &amp;lt;tt&amp;gt;brk&amp;lt;/tt&amp;gt; do?&lt;br /&gt;
A: Change the location of the program break, which defines the end of the process&#039; data segment.&lt;br /&gt;
# What does the &amp;lt;tt&amp;gt;more&amp;lt;/tt&amp;gt; command do?  &lt;br /&gt;
A: a filter for paging through text one screenful at a time.&lt;br /&gt;
# How do you quit the &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
A: allows backward movement in the file as well as forward movement&lt;br /&gt;
&lt;br /&gt;
===Shell Basics===&lt;br /&gt;
&lt;br /&gt;
# The &amp;lt;tt&amp;gt;which&amp;lt;/tt&amp;gt; command can be used to figure out what directory an executable program resides in.  Using this command, what directory contains the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
# &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; is your default shell.  Which of the following is another shell that can be used instead of BASH?&amp;lt;tt&amp;gt; mv, cat, bc, tcsh, or arch &amp;lt;/tt&amp;gt;&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command can be used to get a listing of the files in a directory.  What options are passed to &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; to see all of the files within a directory (including hidden files)?&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command is used to get a list of processes which are running on the system.  Start a new shell from bash by running &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt;.  Does the new shell replace or run in parallel with the old BASH shell?  What about &amp;lt;tt&amp;gt;exec bash&amp;lt;/tt&amp;gt;?  You can use the &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command to determine if bash is still running.&lt;br /&gt;
# Because each process is started by some other process, there is a process tree structure on the system.  From within your bash terminal, determine what process started BASH by using the &amp;lt;tt&amp;gt;pstree&amp;lt;/tt&amp;gt; command.  What graphical application can give you the same information?&lt;br /&gt;
/usr/bin/top&lt;br /&gt;
tcsh&lt;br /&gt;
ls -a&lt;br /&gt;
bash: open a new one.&lt;br /&gt;
exec bash: replace the old one&lt;br /&gt;
init--gnome-terminal--bash&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
Each application running on a system is assigned a unique process identifier.  The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
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 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&lt;br /&gt;
file is always owned by someone and is always associated with a group.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command with the &amp;lt;tt&amp;gt;-l&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
#Who is the owner of the &amp;lt;tt&amp;gt;/etc&amp;lt;/tt&amp;gt; directory?&lt;br /&gt;
A: root&lt;br /&gt;
# What group is associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: shadow&lt;br /&gt;
# Each user is a member of some number of groups.  You can determine what groups you are part of by using the &amp;lt;tt&amp;gt;groups&amp;lt;/tt&amp;gt; command. Based on the groups listed, would you (the ``student&#039;&#039; user in the lab) be a member of the group associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: no&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;echo $HELLO&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
# On the command line, run the following two sets of commands.  Notice that the bash command will start a new shell separate from the shell that the HELLO environment variable was set in.&lt;br /&gt;
&lt;br /&gt;
 HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
 export HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
What does the export command seem to do?&lt;br /&gt;
declare a global variable&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;printf&amp;lt;/tt&amp;gt; is loaded in at run-time.&lt;br /&gt;
&lt;br /&gt;
# Using &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, what dynamic library dependencies does the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command have?&lt;br /&gt;
# In addition to the libraries listed as dependencies for the application &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, there may be other libraries that the application loads dynamically at run-time.  Retrieve the process number &amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt; for the &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; process (using &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) and examine the map file located at &amp;lt;tt&amp;gt;/proc/&amp;lt;/tt&amp;gt;&amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt;&amp;lt;tt&amp;gt;/maps&amp;lt;/tt&amp;gt;.  What other dynamic libraries have been loaded into the application while it has been running?&lt;br /&gt;
&lt;br /&gt;
Linux-gate.so.1, libproc, libncurses, libc, libdl, /lib/ld-linux&lt;br /&gt;
&lt;br /&gt;
=Part B (Optional)=&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; function in a UNIX environment?&lt;br /&gt;
# What is a zombie process?&lt;br /&gt;
# Give an example C program which creates a zombie process.  Note that &amp;lt;tt&amp;gt;BASH&amp;lt;/tt&amp;gt; by default will collect and destroy zombie processes and so you will need to avoid bash destroying the zombie process during debugging.  This can be done by delaying the parent exit (using sleep is one good way to do this).&lt;br /&gt;
# Perform the modifications to your program above to avoid creating a zombie process.  List the new program.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
# Permissions on Unix are grouped into three basic file operations. What are these file operations?&lt;br /&gt;
# What does it mean to have execute permission on a directory?&lt;br /&gt;
# What are the 6 basic file permissions within Windows?&lt;br /&gt;
# What is the difference between the write and modify file permission in Windows?&lt;br /&gt;
# 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 &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command may prove useful).&lt;br /&gt;
# In Windows, a file can be associated with more than one group and each group can have different access permissions.  On Unix, new groups can be created by the system administrator which are supersets of other groups.  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.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
# What does the PATH environment variable do?&lt;br /&gt;
# What environment variable tells X applications where to find the X server which it should communicate with to display the output?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
Dynamic libraries allow one copy of executable code to be used by&lt;br /&gt;
many different processes on the system, without requiring that&lt;br /&gt;
multiple copies of the code be stored on disk in different files.&lt;br /&gt;
What are some problems that can arise when different programs use the&lt;br /&gt;
same common DLLs (hint: ``DLL Hell&#039;&#039;)?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2271</id>
		<title>COMP 3000 Lab 2 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2271"/>
		<updated>2010-09-28T15:16:23Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Environment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following lab requires access to a relatively standard Linux environment.  Use a virtual machine version of Ubuntu or log in to one of the SCS Linux machines.  Alternately, use your own Linux installation (installed natively or in a virtual machine).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note - this lab is not yet finalized!&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Part A (Mandatory)=&lt;br /&gt;
&lt;br /&gt;
==The Shell==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To run a program contained in the current directory in the shell, you need to prefix the name of the command with a &amp;lt;tt&amp;gt;./&amp;lt;/tt&amp;gt;.  This &amp;quot;./&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
===Help===&lt;br /&gt;
&lt;br /&gt;
#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 &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command.  If one wanted to get help on the echo command, the associated command would be &amp;lt;tt&amp;gt;man echo&amp;lt;/tt&amp;gt;.  What does &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; stand for?&lt;br /&gt;
A: echo deisplys a line of text&lt;br /&gt;
#The &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command can also be used to get help on standard C functions.  Briefly (in one line), what does the C function &amp;lt;tt&amp;gt;brk&amp;lt;/tt&amp;gt; do?&lt;br /&gt;
A: Change the location of the program break, which defines the end of the process&#039; data segment.&lt;br /&gt;
# What does the &amp;lt;tt&amp;gt;more&amp;lt;/tt&amp;gt; command do?  &lt;br /&gt;
A: a filter for paging through text one screenful at a time.&lt;br /&gt;
# How do you quit the &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
A: allows backward movement in the file as well as forward movement&lt;br /&gt;
&lt;br /&gt;
===Shell Basics===&lt;br /&gt;
&lt;br /&gt;
# The &amp;lt;tt&amp;gt;which&amp;lt;/tt&amp;gt; command can be used to figure out what directory an executable program resides in.  Using this command, what directory contains the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
# &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; is your default shell.  Which of the following is another shell that can be used instead of BASH?&amp;lt;tt&amp;gt; mv, cat, bc, tcsh, or arch &amp;lt;/tt&amp;gt;&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command can be used to get a listing of the files in a directory.  What options are passed to &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; to see all of the files within a directory (including hidden files)?&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command is used to get a list of processes which are running on the system.  Start a new shell from bash by running &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt;.  Does the new shell replace or run in parallel with the old BASH shell?  What about &amp;lt;tt&amp;gt;exec bash&amp;lt;/tt&amp;gt;?  You can use the &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command to determine if bash is still running.&lt;br /&gt;
# Because each process is started by some other process, there is a process tree structure on the system.  From within your bash terminal, determine what process started BASH by using the &amp;lt;tt&amp;gt;pstree&amp;lt;/tt&amp;gt; command.  What graphical application can give you the same information?&lt;br /&gt;
/usr/bin/top&lt;br /&gt;
tcsh&lt;br /&gt;
ls -a&lt;br /&gt;
bash: open a new one.&lt;br /&gt;
exec bash: replace the old one&lt;br /&gt;
init--gnome-terminal--bash&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
Each application running on a system is assigned a unique process identifier.  The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
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 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&lt;br /&gt;
file is always owned by someone and is always associated with a group.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command with the &amp;lt;tt&amp;gt;-l&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
#Who is the owner of the &amp;lt;tt&amp;gt;/etc&amp;lt;/tt&amp;gt; directory?&lt;br /&gt;
A: root&lt;br /&gt;
# What group is associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: shadow&lt;br /&gt;
# Each user is a member of some number of groups.  You can determine what groups you are part of by using the &amp;lt;tt&amp;gt;groups&amp;lt;/tt&amp;gt; command. Based on the groups listed, would you (the ``student&#039;&#039; user in the lab) be a member of the group associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: no&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;echo $HELLO&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
# On the command line, run the following two sets of commands.  Notice that the bash command will start a new shell separate from the shell that the HELLO environment variable was set in.&lt;br /&gt;
&lt;br /&gt;
 HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
 export HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
What does the export command seem to do?&lt;br /&gt;
declare a global variable&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;printf&amp;lt;/tt&amp;gt; is loaded in at run-time.&lt;br /&gt;
&lt;br /&gt;
# Using &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, what dynamic library dependencies does the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command have?&lt;br /&gt;
# In addition to the libraries listed as dependencies for the application &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, there may be other libraries that the application loads dynamically at run-time.  Retrieve the process number &amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt; for the &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; process (using &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) and examine the map file located at &amp;lt;tt&amp;gt;/proc/&amp;lt;/tt&amp;gt;&amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt;&amp;lt;tt&amp;gt;/maps&amp;lt;/tt&amp;gt;.  What other dynamic libraries have been loaded into the application while it has been running?&lt;br /&gt;
&lt;br /&gt;
=Part B (Optional)=&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; function in a UNIX environment?&lt;br /&gt;
# What is a zombie process?&lt;br /&gt;
# Give an example C program which creates a zombie process.  Note that &amp;lt;tt&amp;gt;BASH&amp;lt;/tt&amp;gt; by default will collect and destroy zombie processes and so you will need to avoid bash destroying the zombie process during debugging.  This can be done by delaying the parent exit (using sleep is one good way to do this).&lt;br /&gt;
# Perform the modifications to your program above to avoid creating a zombie process.  List the new program.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
# Permissions on Unix are grouped into three basic file operations. What are these file operations?&lt;br /&gt;
# What does it mean to have execute permission on a directory?&lt;br /&gt;
# What are the 6 basic file permissions within Windows?&lt;br /&gt;
# What is the difference between the write and modify file permission in Windows?&lt;br /&gt;
# 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 &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command may prove useful).&lt;br /&gt;
# In Windows, a file can be associated with more than one group and each group can have different access permissions.  On Unix, new groups can be created by the system administrator which are supersets of other groups.  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.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
# What does the PATH environment variable do?&lt;br /&gt;
# What environment variable tells X applications where to find the X server which it should communicate with to display the output?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
Dynamic libraries allow one copy of executable code to be used by&lt;br /&gt;
many different processes on the system, without requiring that&lt;br /&gt;
multiple copies of the code be stored on disk in different files.&lt;br /&gt;
What are some problems that can arise when different programs use the&lt;br /&gt;
same common DLLs (hint: ``DLL Hell&#039;&#039;)?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2270</id>
		<title>COMP 3000 Lab 2 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2270"/>
		<updated>2010-09-28T15:12:02Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Shell Basics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following lab requires access to a relatively standard Linux environment.  Use a virtual machine version of Ubuntu or log in to one of the SCS Linux machines.  Alternately, use your own Linux installation (installed natively or in a virtual machine).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note - this lab is not yet finalized!&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Part A (Mandatory)=&lt;br /&gt;
&lt;br /&gt;
==The Shell==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To run a program contained in the current directory in the shell, you need to prefix the name of the command with a &amp;lt;tt&amp;gt;./&amp;lt;/tt&amp;gt;.  This &amp;quot;./&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
===Help===&lt;br /&gt;
&lt;br /&gt;
#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 &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command.  If one wanted to get help on the echo command, the associated command would be &amp;lt;tt&amp;gt;man echo&amp;lt;/tt&amp;gt;.  What does &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; stand for?&lt;br /&gt;
A: echo deisplys a line of text&lt;br /&gt;
#The &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command can also be used to get help on standard C functions.  Briefly (in one line), what does the C function &amp;lt;tt&amp;gt;brk&amp;lt;/tt&amp;gt; do?&lt;br /&gt;
A: Change the location of the program break, which defines the end of the process&#039; data segment.&lt;br /&gt;
# What does the &amp;lt;tt&amp;gt;more&amp;lt;/tt&amp;gt; command do?  &lt;br /&gt;
A: a filter for paging through text one screenful at a time.&lt;br /&gt;
# How do you quit the &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
A: allows backward movement in the file as well as forward movement&lt;br /&gt;
&lt;br /&gt;
===Shell Basics===&lt;br /&gt;
&lt;br /&gt;
# The &amp;lt;tt&amp;gt;which&amp;lt;/tt&amp;gt; command can be used to figure out what directory an executable program resides in.  Using this command, what directory contains the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
# &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; is your default shell.  Which of the following is another shell that can be used instead of BASH?&amp;lt;tt&amp;gt; mv, cat, bc, tcsh, or arch &amp;lt;/tt&amp;gt;&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command can be used to get a listing of the files in a directory.  What options are passed to &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; to see all of the files within a directory (including hidden files)?&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command is used to get a list of processes which are running on the system.  Start a new shell from bash by running &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt;.  Does the new shell replace or run in parallel with the old BASH shell?  What about &amp;lt;tt&amp;gt;exec bash&amp;lt;/tt&amp;gt;?  You can use the &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command to determine if bash is still running.&lt;br /&gt;
# Because each process is started by some other process, there is a process tree structure on the system.  From within your bash terminal, determine what process started BASH by using the &amp;lt;tt&amp;gt;pstree&amp;lt;/tt&amp;gt; command.  What graphical application can give you the same information?&lt;br /&gt;
/usr/bin/top&lt;br /&gt;
tcsh&lt;br /&gt;
ls -a&lt;br /&gt;
bash: open a new one.&lt;br /&gt;
exec bash: replace the old one&lt;br /&gt;
init--gnome-terminal--bash&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
Each application running on a system is assigned a unique process identifier.  The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
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 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&lt;br /&gt;
file is always owned by someone and is always associated with a group.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command with the &amp;lt;tt&amp;gt;-l&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
#Who is the owner of the &amp;lt;tt&amp;gt;/etc&amp;lt;/tt&amp;gt; directory?&lt;br /&gt;
A: root&lt;br /&gt;
# What group is associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: shadow&lt;br /&gt;
# Each user is a member of some number of groups.  You can determine what groups you are part of by using the &amp;lt;tt&amp;gt;groups&amp;lt;/tt&amp;gt; command. Based on the groups listed, would you (the ``student&#039;&#039; user in the lab) be a member of the group associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: no&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;echo $HELLO&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
# On the command line, run the following two sets of commands.  Notice that the bash command will start a new shell separate from the shell that the HELLO environment variable was set in.&lt;br /&gt;
&lt;br /&gt;
 HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
 export HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
What does the export command seem to do?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;printf&amp;lt;/tt&amp;gt; is loaded in at run-time.&lt;br /&gt;
&lt;br /&gt;
# Using &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, what dynamic library dependencies does the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command have?&lt;br /&gt;
# In addition to the libraries listed as dependencies for the application &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, there may be other libraries that the application loads dynamically at run-time.  Retrieve the process number &amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt; for the &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; process (using &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) and examine the map file located at &amp;lt;tt&amp;gt;/proc/&amp;lt;/tt&amp;gt;&amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt;&amp;lt;tt&amp;gt;/maps&amp;lt;/tt&amp;gt;.  What other dynamic libraries have been loaded into the application while it has been running?&lt;br /&gt;
&lt;br /&gt;
=Part B (Optional)=&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; function in a UNIX environment?&lt;br /&gt;
# What is a zombie process?&lt;br /&gt;
# Give an example C program which creates a zombie process.  Note that &amp;lt;tt&amp;gt;BASH&amp;lt;/tt&amp;gt; by default will collect and destroy zombie processes and so you will need to avoid bash destroying the zombie process during debugging.  This can be done by delaying the parent exit (using sleep is one good way to do this).&lt;br /&gt;
# Perform the modifications to your program above to avoid creating a zombie process.  List the new program.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
# Permissions on Unix are grouped into three basic file operations. What are these file operations?&lt;br /&gt;
# What does it mean to have execute permission on a directory?&lt;br /&gt;
# What are the 6 basic file permissions within Windows?&lt;br /&gt;
# What is the difference between the write and modify file permission in Windows?&lt;br /&gt;
# 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 &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command may prove useful).&lt;br /&gt;
# In Windows, a file can be associated with more than one group and each group can have different access permissions.  On Unix, new groups can be created by the system administrator which are supersets of other groups.  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.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
# What does the PATH environment variable do?&lt;br /&gt;
# What environment variable tells X applications where to find the X server which it should communicate with to display the output?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
Dynamic libraries allow one copy of executable code to be used by&lt;br /&gt;
many different processes on the system, without requiring that&lt;br /&gt;
multiple copies of the code be stored on disk in different files.&lt;br /&gt;
What are some problems that can arise when different programs use the&lt;br /&gt;
same common DLLs (hint: ``DLL Hell&#039;&#039;)?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2268</id>
		<title>COMP 3000 Lab 2 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2268"/>
		<updated>2010-09-28T15:00:52Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Permissions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following lab requires access to a relatively standard Linux environment.  Use a virtual machine version of Ubuntu or log in to one of the SCS Linux machines.  Alternately, use your own Linux installation (installed natively or in a virtual machine).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note - this lab is not yet finalized!&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Part A (Mandatory)=&lt;br /&gt;
&lt;br /&gt;
==The Shell==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To run a program contained in the current directory in the shell, you need to prefix the name of the command with a &amp;lt;tt&amp;gt;./&amp;lt;/tt&amp;gt;.  This &amp;quot;./&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
===Help===&lt;br /&gt;
&lt;br /&gt;
#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 &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command.  If one wanted to get help on the echo command, the associated command would be &amp;lt;tt&amp;gt;man echo&amp;lt;/tt&amp;gt;.  What does &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; stand for?&lt;br /&gt;
A: echo deisplys a line of text&lt;br /&gt;
#The &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command can also be used to get help on standard C functions.  Briefly (in one line), what does the C function &amp;lt;tt&amp;gt;brk&amp;lt;/tt&amp;gt; do?&lt;br /&gt;
A: Change the location of the program break, which defines the end of the process&#039; data segment.&lt;br /&gt;
# What does the &amp;lt;tt&amp;gt;more&amp;lt;/tt&amp;gt; command do?  &lt;br /&gt;
A: a filter for paging through text one screenful at a time.&lt;br /&gt;
# How do you quit the &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
A: allows backward movement in the file as well as forward movement&lt;br /&gt;
&lt;br /&gt;
===Shell Basics===&lt;br /&gt;
&lt;br /&gt;
# The &amp;lt;tt&amp;gt;which&amp;lt;/tt&amp;gt; command can be used to figure out what directory an executable program resides in.  Using this command, what directory contains the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
# &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; is your default shell.  Which of the following is another shell that can be used instead of BASH?&amp;lt;tt&amp;gt; mv, cat, bc, tcsh, or arch &amp;lt;/tt&amp;gt;&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command can be used to get a listing of the files in a directory.  What options are passed to &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; to see all of the files within a directory (including hidden files)?&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command is used to get a list of processes which are running on the system.  Start a new shell from bash by running &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt;.  Does the new shell replace or run in parallel with the old BASH shell?  What about &amp;lt;tt&amp;gt;exec bash&amp;lt;/tt&amp;gt;?  You can use the &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command to determine if bash is still running.&lt;br /&gt;
# Because each process is started by some other process, there is a process tree structure on the system.  From within your bash terminal, determine what process started BASH by using the &amp;lt;tt&amp;gt;pstree&amp;lt;/tt&amp;gt; command.  What graphical application can give you the same information?&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
Each application running on a system is assigned a unique process identifier.  The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
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 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&lt;br /&gt;
file is always owned by someone and is always associated with a group.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command with the &amp;lt;tt&amp;gt;-l&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
#Who is the owner of the &amp;lt;tt&amp;gt;/etc&amp;lt;/tt&amp;gt; directory?&lt;br /&gt;
A: root&lt;br /&gt;
# What group is associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: shadow&lt;br /&gt;
# Each user is a member of some number of groups.  You can determine what groups you are part of by using the &amp;lt;tt&amp;gt;groups&amp;lt;/tt&amp;gt; command. Based on the groups listed, would you (the ``student&#039;&#039; user in the lab) be a member of the group associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
A: no&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;echo $HELLO&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
# On the command line, run the following two sets of commands.  Notice that the bash command will start a new shell separate from the shell that the HELLO environment variable was set in.&lt;br /&gt;
&lt;br /&gt;
 HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
 export HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
What does the export command seem to do?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;printf&amp;lt;/tt&amp;gt; is loaded in at run-time.&lt;br /&gt;
&lt;br /&gt;
# Using &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, what dynamic library dependencies does the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command have?&lt;br /&gt;
# In addition to the libraries listed as dependencies for the application &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, there may be other libraries that the application loads dynamically at run-time.  Retrieve the process number &amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt; for the &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; process (using &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) and examine the mmap file located at &amp;lt;tt&amp;gt;/proc/&amp;lt;/tt&amp;gt;&amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt;&amp;lt;tt&amp;gt;/maps&amp;lt;/tt&amp;gt;.  What other dynamic libraries have been loaded into the application while it has been running?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Part B (Optional)=&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; function in a UNIX environment?&lt;br /&gt;
# What is a zombie process?&lt;br /&gt;
# Give an example C program which creates a zombie process.  Note that &amp;lt;tt&amp;gt;BASH&amp;lt;/tt&amp;gt; by default will collect and destroy zombie processes and so you will need to avoid bash destroying the zombie process during debugging.  This can be done by delaying the parent exit (using sleep is one good way to do this).&lt;br /&gt;
# Perform the modifications to your program above to avoid creating a zombie process.  List the new program.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
# Permissions on Unix are grouped into three basic file operations. What are these file operations?&lt;br /&gt;
# What does it mean to have execute permission on a directory?&lt;br /&gt;
# What are the 6 basic file permissions within Windows?&lt;br /&gt;
# What is the difference between the write and modify file permission in Windows?&lt;br /&gt;
# 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 &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command may prove useful).&lt;br /&gt;
# In Windows, a file can be associated with more than one group and each group can have different access permissions.  On Unix, new groups can be created by the system administrator which are supersets of other groups.  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.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
# What does the PATH environment variable do?&lt;br /&gt;
# What environment variable tells X applications where to find the X server which it should communicate with to display the output?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
Dynamic libraries allow one copy of executable code to be used by&lt;br /&gt;
many different processes on the system, without requiring that&lt;br /&gt;
multiple copies of the code be stored on disk in different files.&lt;br /&gt;
What are some problems that can arise when different programs use the&lt;br /&gt;
same common DLLs (hint: ``DLL Hell&#039;&#039;)?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2267</id>
		<title>COMP 3000 Lab 2 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2010&amp;diff=2267"/>
		<updated>2010-09-28T14:54:51Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Help */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;The following lab requires access to a relatively standard Linux environment.  Use a virtual machine version of Ubuntu or log in to one of the SCS Linux machines.  Alternately, use your own Linux installation (installed natively or in a virtual machine).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;b&amp;gt;Note - this lab is not yet finalized!&amp;lt;/b&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=Part A (Mandatory)=&lt;br /&gt;
&lt;br /&gt;
==The Shell==&lt;br /&gt;
&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
To run a program contained in the current directory in the shell, you need to prefix the name of the command with a &amp;lt;tt&amp;gt;./&amp;lt;/tt&amp;gt;.  This &amp;quot;./&amp;quot; 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.&lt;br /&gt;
&lt;br /&gt;
===Help===&lt;br /&gt;
&lt;br /&gt;
#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 &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command.  If one wanted to get help on the echo command, the associated command would be &amp;lt;tt&amp;gt;man echo&amp;lt;/tt&amp;gt;.  What does &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; stand for?&lt;br /&gt;
A: echo deisplys a line of text&lt;br /&gt;
#The &amp;lt;tt&amp;gt;man&amp;lt;/tt&amp;gt; command can also be used to get help on standard C functions.  Briefly (in one line), what does the C function &amp;lt;tt&amp;gt;brk&amp;lt;/tt&amp;gt; do?&lt;br /&gt;
A: Change the location of the program break, which defines the end of the process&#039; data segment.&lt;br /&gt;
# What does the &amp;lt;tt&amp;gt;more&amp;lt;/tt&amp;gt; command do?  &lt;br /&gt;
A: a filter for paging through text one screenful at a time.&lt;br /&gt;
# How do you quit the &amp;lt;tt&amp;gt;less&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
A: allows backward movement in the file as well as forward movement&lt;br /&gt;
&lt;br /&gt;
===Shell Basics===&lt;br /&gt;
&lt;br /&gt;
# The &amp;lt;tt&amp;gt;which&amp;lt;/tt&amp;gt; command can be used to figure out what directory an executable program resides in.  Using this command, what directory contains the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command?&lt;br /&gt;
# &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; is your default shell.  Which of the following is another shell that can be used instead of BASH?&amp;lt;tt&amp;gt; mv, cat, bc, tcsh, or arch &amp;lt;/tt&amp;gt;&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command can be used to get a listing of the files in a directory.  What options are passed to &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; to see all of the files within a directory (including hidden files)?&lt;br /&gt;
# The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command is used to get a list of processes which are running on the system.  Start a new shell from bash by running &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt;.  Does the new shell replace or run in parallel with the old BASH shell?  What about &amp;lt;tt&amp;gt;exec bash&amp;lt;/tt&amp;gt;?  You can use the &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; command to determine if bash is still running.&lt;br /&gt;
# Because each process is started by some other process, there is a process tree structure on the system.  From within your bash terminal, determine what process started BASH by using the &amp;lt;tt&amp;gt;pstree&amp;lt;/tt&amp;gt; command.  What graphical application can give you the same information?&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
Each application running on a system is assigned a unique process identifier.  The &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
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 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&lt;br /&gt;
file is always owned by someone and is always associated with a group.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;ls&amp;lt;/tt&amp;gt; command with the &amp;lt;tt&amp;gt;-l&amp;lt;/tt&amp;gt; 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.&lt;br /&gt;
&lt;br /&gt;
#Who is the owner of the &amp;lt;tt&amp;gt;/etc&amp;lt;/tt&amp;gt; directory?&lt;br /&gt;
# What group is associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
# Each user is a member of some number of groups.  You can determine what groups you are part of by using the &amp;lt;tt&amp;gt;groups&amp;lt;/tt&amp;gt; command. Based on the groups listed, would you (the ``student&#039;&#039; user in the lab) be a member of the group associated with the &amp;lt;tt&amp;gt;/etc/shadow&amp;lt;/tt&amp;gt; file?&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;echo $HELLO&amp;lt;/tt&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
# On the command line, run the following two sets of commands.  Notice that the bash command will start a new shell separate from the shell that the HELLO environment variable was set in.&lt;br /&gt;
&lt;br /&gt;
 HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
 export HELLO=&amp;quot;Hi There&amp;quot;&lt;br /&gt;
 bash&lt;br /&gt;
 echo $HELLO&lt;br /&gt;
 exit&lt;br /&gt;
&lt;br /&gt;
What does the export command seem to do?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
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 &amp;lt;tt&amp;gt;printf&amp;lt;/tt&amp;gt; is loaded in at run-time.&lt;br /&gt;
&lt;br /&gt;
# Using &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, what dynamic library dependencies does the &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; command have?&lt;br /&gt;
# In addition to the libraries listed as dependencies for the application &amp;lt;tt&amp;gt;top&amp;lt;/tt&amp;gt; by &amp;lt;tt&amp;gt;ldd&amp;lt;/tt&amp;gt;, there may be other libraries that the application loads dynamically at run-time.  Retrieve the process number &amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt; for the &amp;lt;tt&amp;gt;bash&amp;lt;/tt&amp;gt; process (using &amp;lt;tt&amp;gt;ps&amp;lt;/tt&amp;gt;) and examine the mmap file located at &amp;lt;tt&amp;gt;/proc/&amp;lt;/tt&amp;gt;&amp;lt;em&amp;gt;PID&amp;lt;/em&amp;gt;&amp;lt;tt&amp;gt;/maps&amp;lt;/tt&amp;gt;.  What other dynamic libraries have been loaded into the application while it has been running?&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=Part B (Optional)=&lt;br /&gt;
&lt;br /&gt;
==Processes==&lt;br /&gt;
&lt;br /&gt;
# What is the difference between the &amp;lt;tt&amp;gt;fork&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;exec&amp;lt;/tt&amp;gt; function in a UNIX environment?&lt;br /&gt;
# What is a zombie process?&lt;br /&gt;
# Give an example C program which creates a zombie process.  Note that &amp;lt;tt&amp;gt;BASH&amp;lt;/tt&amp;gt; by default will collect and destroy zombie processes and so you will need to avoid bash destroying the zombie process during debugging.  This can be done by delaying the parent exit (using sleep is one good way to do this).&lt;br /&gt;
# Perform the modifications to your program above to avoid creating a zombie process.  List the new program.&lt;br /&gt;
&lt;br /&gt;
==Permissions==&lt;br /&gt;
&lt;br /&gt;
# Permissions on Unix are grouped into three basic file operations. What are these file operations?&lt;br /&gt;
# What does it mean to have execute permission on a directory?&lt;br /&gt;
# What are the 6 basic file permissions within Windows?&lt;br /&gt;
# What is the difference between the write and modify file permission in Windows?&lt;br /&gt;
# 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 &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command may prove useful).&lt;br /&gt;
# In Windows, a file can be associated with more than one group and each group can have different access permissions.  On Unix, new groups can be created by the system administrator which are supersets of other groups.  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.&lt;br /&gt;
&lt;br /&gt;
==Environment==&lt;br /&gt;
&lt;br /&gt;
# What does the PATH environment variable do?&lt;br /&gt;
# What environment variable tells X applications where to find the X server which it should communicate with to display the output?&lt;br /&gt;
&lt;br /&gt;
==Dynamic Libraries==&lt;br /&gt;
&lt;br /&gt;
Dynamic libraries allow one copy of executable code to be used by&lt;br /&gt;
many different processes on the system, without requiring that&lt;br /&gt;
multiple copies of the code be stored on disk in different files.&lt;br /&gt;
What are some problems that can arise when different programs use the&lt;br /&gt;
same common DLLs (hint: ``DLL Hell&#039;&#039;)?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_1_2010&amp;diff=2234</id>
		<title>COMP 3000 Lab 1 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_1_2010&amp;diff=2234"/>
		<updated>2010-09-24T19:37:49Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Part A (Mandatory) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
# Create a virtual machine in VirtualBox for Ubuntu Linux and install Ubuntu using the ISO image in C:\support\somayaji.&lt;br /&gt;
#*Create your disk image on your Desktop or on a USB stick.&lt;br /&gt;
#*Images on your desktop will be deleted when you log out; USB stick images will be slower to access.&lt;br /&gt;
#*USB sticks may need to be formatted with NTFS to support a VirtualBox image. &lt;br /&gt;
#*Create a fixed-sized disk to increase performance.  However, you&#039;ll then have to wait for the fixed-sized disk to be allocated.&lt;br /&gt;
#*If you wish, you can use the Ubuntu install ISO as a live CD image.  In this case you don&#039;t need to install to any virtual hard disks.&lt;br /&gt;
#Create an account on the class wiki.  If you choose not to use your connect username please email me with your real name and your wiki username.&lt;br /&gt;
# Install the guest additions to your Ubuntu guest.  What new capabilities do you get?&lt;br /&gt;
#*To install, first mount the guest additions ISO using the &amp;quot;Devices&amp;quot; VirtualBox menu option.&lt;br /&gt;
#*To run the additions script, start up a Terminal window and run &amp;quot;sudo sh /media/&amp;lt;VBOXADD...&amp;gt;/VBoxLinuxAdditions-x86.run&amp;quot;.&lt;br /&gt;
new capablities: shared folder support, OpenGL support, etc.&lt;br /&gt;
&lt;br /&gt;
# How much RAM does the VM use on the host?  How much is available in the VM?&lt;br /&gt;
512MB. 497.3MB.&lt;br /&gt;
# Look at the Disk Utility application in Ubuntu.  What sort of storage hardware does it have?  How does this compare to the hardware on the Windows host?&lt;br /&gt;
CD Drive and hard Disk. Hard disk is 8.6GB. We assign 8G as fixed size disk, why it shows 8.6G in Disk Utility?&lt;br /&gt;
# Look at /proc/cpuinfo in the Ubuntu guest - is the CPU the same as that reported by Windows?&lt;br /&gt;
&lt;br /&gt;
Yes.&lt;br /&gt;
# What about the PCI devices as reported by the command line program &amp;quot;lspci&amp;quot;?&lt;br /&gt;
Guest OS can use all the PCI devices as the host can use.&lt;br /&gt;
# How does the performance of the VM compare to that of the host OS?  Examine GUI, disk, and network performance.&lt;br /&gt;
almost same as host.&lt;br /&gt;
Feel free to add your tips for the above exercises here.&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
#Run benchmarks in the guest and host OSs such as lmbench for Linux.&lt;br /&gt;
#*Tip: phoronix-test-suite, rambench, cpuburn, bashmark, forkbomb&lt;br /&gt;
#Enable support for flash and non-free codecs in Ubuntu.&lt;br /&gt;
#Create an Ubuntu virtual machine in VMWare Player.  How does the performance of VMWare and VirtualBox compare?&lt;br /&gt;
#Can you run VirtualBox in the Ubuntu guest?  Note that VirtualBox is part of the Ubuntu distribution already.&lt;br /&gt;
# Setup shared folders between the guest and host and verify that you can copy files both ways.  What does the shared folder look like to Ubuntu?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_1_2010&amp;diff=2233</id>
		<title>COMP 3000 Lab 1 2010</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_1_2010&amp;diff=2233"/>
		<updated>2010-09-24T19:31:29Z</updated>

		<summary type="html">&lt;p&gt;Zliu10: /* Part A (Mandatory) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Part A (Mandatory)==&lt;br /&gt;
&lt;br /&gt;
This part is to be completed in class.&lt;br /&gt;
&lt;br /&gt;
You may add or edit tips after each question; please do not edit the original question, however.&lt;br /&gt;
&lt;br /&gt;
# Create a virtual machine in VirtualBox for Ubuntu Linux and install Ubuntu using the ISO image in C:\support\somayaji.&lt;br /&gt;
#*Create your disk image on your Desktop or on a USB stick.&lt;br /&gt;
#*Images on your desktop will be deleted when you log out; USB stick images will be slower to access.&lt;br /&gt;
#*USB sticks may need to be formatted with NTFS to support a VirtualBox image. &lt;br /&gt;
#*Create a fixed-sized disk to increase performance.  However, you&#039;ll then have to wait for the fixed-sized disk to be allocated.&lt;br /&gt;
#*If you wish, you can use the Ubuntu install ISO as a live CD image.  In this case you don&#039;t need to install to any virtual hard disks.&lt;br /&gt;
#Create an account on the class wiki.  If you choose not to use your connect username please email me with your real name and your wiki username.&lt;br /&gt;
# Install the guest additions to your Ubuntu guest.  What new capabilities do you get?&lt;br /&gt;
#*To install, first mount the guest additions ISO using the &amp;quot;Devices&amp;quot; VirtualBox menu option.&lt;br /&gt;
#*To run the additions script, start up a Terminal window and run &amp;quot;sudo sh /media/&amp;lt;VBOXADD...&amp;gt;/VBoxLinuxAdditions-x86.run&amp;quot;.&lt;br /&gt;
new capablities: shared folder support, OpenGL support, etc.&lt;br /&gt;
&lt;br /&gt;
# How much RAM does the VM use on the host?  How much is available in the VM?&lt;br /&gt;
512MB. 497.3MB.&lt;br /&gt;
# Look at the Disk Utility application in Ubuntu.  What sort of storage hardware does it have?  How does this compare to the hardware on the Windows host?&lt;br /&gt;
CD Drive and hard Disk. Hard disk is 8.6GB. We assign this value while installing Virtual Machine.&lt;br /&gt;
# Look at /proc/cpuinfo in the Ubuntu guest - is the CPU the same as that reported by Windows?&lt;br /&gt;
&lt;br /&gt;
Yes.&lt;br /&gt;
# What about the PCI devices as reported by the command line program &amp;quot;lspci&amp;quot;?&lt;br /&gt;
Guest OS can use all the PCI devices as the host can use.&lt;br /&gt;
# How does the performance of the VM compare to that of the host OS?  Examine GUI, disk, and network performance.&lt;br /&gt;
almost same as host.&lt;br /&gt;
Feel free to add your tips for the above exercises here.&lt;br /&gt;
&lt;br /&gt;
==Part B (Optional)==&lt;br /&gt;
&lt;br /&gt;
The following exercises are optional.&lt;br /&gt;
&lt;br /&gt;
#Run benchmarks in the guest and host OSs such as lmbench for Linux.&lt;br /&gt;
#*Tip: phoronix-test-suite, rambench, cpuburn, bashmark, forkbomb&lt;br /&gt;
#Enable support for flash and non-free codecs in Ubuntu.&lt;br /&gt;
#Create an Ubuntu virtual machine in VMWare Player.  How does the performance of VMWare and VirtualBox compare?&lt;br /&gt;
#Can you run VirtualBox in the Ubuntu guest?  Note that VirtualBox is part of the Ubuntu distribution already.&lt;br /&gt;
# Setup shared folders between the guest and host and verify that you can copy files both ways.  What does the shared folder look like to Ubuntu?&lt;/div&gt;</summary>
		<author><name>Zliu10</name></author>
	</entry>
</feed>