<?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=Jbeltram</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=Jbeltram"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php/Special:Contributions/Jbeltram"/>
	<updated>2026-04-05T01:44:34Z</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_6_2012&amp;diff=17605</id>
		<title>COMP 3000 Lab 6 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_6_2012&amp;diff=17605"/>
		<updated>2012-11-19T15:59:11Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;This lab is due on Friday, Nov. 9, at 11:55 PM.  This lab has 16 points.&lt;br /&gt;
&lt;br /&gt;
Run the following three commands in bash.  (Note the \ is just to note the command continues on the following line.)&lt;br /&gt;
&lt;br /&gt;
 x=0; while builtin test $x -lt 50000; do echo &amp;quot;P1 C1 $x&amp;quot;; echo &amp;quot;P1 C2 $x&amp;quot;; \&lt;br /&gt;
   echo &amp;quot;P1 C3 $x&amp;quot;; let x=$(($x + 1)); done &amp;gt;&amp;gt; race.txt &amp;amp;&lt;br /&gt;
 y=0; while builtin test $y -lt 50000; do echo &amp;quot;P2 C1 $y&amp;quot;; echo &amp;quot;P2 C2 $y&amp;quot;; \&lt;br /&gt;
   echo &amp;quot;P2 C3 $y&amp;quot;; let y=$(($y + 1)); done &amp;gt;&amp;gt; race.txt &amp;amp;&lt;br /&gt;
&lt;br /&gt;
The following questions are based on these three lines.&lt;br /&gt;
&lt;br /&gt;
# [2] Describe the output of the above lines.  In particular, how is the output of the two commands intermingled in the file race.txt?&lt;br /&gt;
# [2] How could you modify the lines so that output to the file race.txt continues until the files &amp;quot;P1-done&amp;quot; or &amp;quot;P2-done&amp;quot; are created in the current directory (instead of testing the values of x and y)?&lt;br /&gt;
# [2] Approximately how many processes do these two lines generate on your system?  How can you tell?&lt;br /&gt;
# [2] Change each line into a stand-alone shell script with no semicolons.&lt;br /&gt;
# [4] Change the shell scripts so that they never run concurrently using the flock command.  If one is running, then the other should wait until it is finished.&lt;br /&gt;
# [4] Use flock in the shell script versions of the commands to keep the output of the three echo&#039;s in the inner loop from being broken apart (make them &amp;quot;atomic&amp;quot;).  Thus, in race.txt, you&#039;ll have lines starting with:&lt;br /&gt;
  P1 C1 ...&lt;br /&gt;
  P1 C2 ...&lt;br /&gt;
  P1 C3 ...&lt;br /&gt;
  P2 C1 ...&lt;br /&gt;
  P2 C2 ...&lt;br /&gt;
  P2 C3 ...&lt;br /&gt;
  P2 C1 ...&lt;br /&gt;
  P2 C2 ...&lt;br /&gt;
  P2 C3 ...&lt;br /&gt;
  P1 C1 ...&lt;br /&gt;
  P1 C2 ...&lt;br /&gt;
  P1 C3 ...&lt;br /&gt;
Note that the interleaving of output from P1 and P2 can be in any order so long as the sequence for each is always C1, C2, then C3.  NOTE: You may want to avoid doing this on a non-local filesystem, e.g., don&#039;t put race.txt in your home directory on the Lambda machines.  Doing this in a VM should work fine.&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
# The output of the two commands is randomly interleaved.  The output is however numerically sequential for both P1 and P2.&lt;br /&gt;
# x=0; while ! builtin test -e p1-done; do echo &amp;quot;P1 C1 $x&amp;quot;; echo &amp;quot;P1 C2 $x&amp;quot;; \ echo &amp;quot;P1 C3 $x&amp;quot;; done &amp;gt;&amp;gt; race.txt &amp;amp; &amp;lt;br&amp;gt; y=0; while ! builtin test -e p2-done; do echo &amp;quot;P2 C1 $y&amp;quot;; echo &amp;quot;P2 C2 $y&amp;quot;; \ echo &amp;quot;P2 C3 $y&amp;quot;; done &amp;gt;&amp;gt; race.txt &amp;amp;&lt;br /&gt;
# These two lines generate approximately two process on the system.  This can be determined using the ps command.&lt;br /&gt;
# See code below.&lt;br /&gt;
# See code below.&lt;br /&gt;
# See code below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang =&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#Number 4 shell scripts&lt;br /&gt;
#!/bin/bash &lt;br /&gt;
x=0 &lt;br /&gt;
while builtin test $x -lt 50000 &lt;br /&gt;
do &lt;br /&gt;
	echo &amp;quot;P1 C1 $x&amp;quot; &lt;br /&gt;
	echo &amp;quot;P1 C2 $x&amp;quot; &lt;br /&gt;
	echo &amp;quot;P1 C3 $x&amp;quot; &lt;br /&gt;
	let x=$(($x + 1))&lt;br /&gt;
done &amp;gt;&amp;gt; race.txt&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
y=0&lt;br /&gt;
while builtin test $y -lt 50000&lt;br /&gt;
do &lt;br /&gt;
	echo &amp;quot;P2 C1 $y&amp;quot;&lt;br /&gt;
	echo &amp;quot;P2 C2 $y&amp;quot;&lt;br /&gt;
	echo &amp;quot;P2 C3 $y&amp;quot;&lt;br /&gt;
	let y=$(($y + 1))&lt;br /&gt;
done &amp;gt;&amp;gt; race.txt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#Number 5 shell scripts&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
(&lt;br /&gt;
flock -x 200&lt;br /&gt;
x=0 &lt;br /&gt;
while builtin test $x -lt 50000 &lt;br /&gt;
do &lt;br /&gt;
	echo &amp;quot;P1 C1 $x&amp;quot; &lt;br /&gt;
	echo &amp;quot;P1 C2 $x&amp;quot; &lt;br /&gt;
	echo &amp;quot;P1 C3 $x&amp;quot; &lt;br /&gt;
	let x=$(($x + 1))&lt;br /&gt;
done &amp;gt;&amp;gt; race.txt&lt;br /&gt;
)200&amp;gt;/var/lock/.myscript.exclusivelock&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
(&lt;br /&gt;
flock -x 200&lt;br /&gt;
y=0&lt;br /&gt;
while builtin test $y -lt 50000&lt;br /&gt;
do &lt;br /&gt;
	echo &amp;quot;P2 C1 $y&amp;quot;&lt;br /&gt;
	echo &amp;quot;P2 C2 $y&amp;quot;&lt;br /&gt;
	echo &amp;quot;P2 C3 $y&amp;quot;&lt;br /&gt;
	let y=$(($y + 1))&lt;br /&gt;
done &amp;gt;&amp;gt; race.txt&lt;br /&gt;
)200&amp;gt;/var/lock/.myscript.exclusivelock&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#Number 6 shell scripts&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
x=0 &lt;br /&gt;
while builtin test $x -lt 50000 &lt;br /&gt;
do &lt;br /&gt;
(&lt;br /&gt;
flock -x 200&lt;br /&gt;
	echo &amp;quot;P1 C1 $x&amp;quot; &lt;br /&gt;
	echo &amp;quot;P1 C2 $x&amp;quot; &lt;br /&gt;
	echo &amp;quot;P1 C3 $x&amp;quot; &lt;br /&gt;
)200&amp;gt;/var/lock/.myscript.exclusivelock&lt;br /&gt;
let x=$(($x + 1))&lt;br /&gt;
done &amp;gt;&amp;gt; race.txt&lt;br /&gt;
#!/bin/bash&lt;br /&gt;
y=0&lt;br /&gt;
while builtin test $y -lt 50000&lt;br /&gt;
do &lt;br /&gt;
(&lt;br /&gt;
flock -x 200&lt;br /&gt;
	echo &amp;quot;P2 C1 $y&amp;quot;&lt;br /&gt;
	echo &amp;quot;P2 C2 $y&amp;quot;&lt;br /&gt;
	echo &amp;quot;P2 C3 $y&amp;quot;&lt;br /&gt;
)200&amp;gt;/var/lock/.myscript.exclusivelock&lt;br /&gt;
let y=$(($y + 1))&lt;br /&gt;
done &amp;gt;&amp;gt; race.txt&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17485</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17485"/>
		<updated>2012-10-24T15:32:28Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
#See code.&lt;br /&gt;
#See code.&lt;br /&gt;
#Loopback mounts could be useful to mount the VM filesystem on the hosts physical disk as a block device.  To be able to do this, the VM software must use the same format for its filesystem as the host&#039;s physical disk, or block device.&lt;br /&gt;
&lt;br /&gt;
 1.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 {&lt;br /&gt;
 	int file = open(&amp;quot;helloworld&amp;quot;, O_RDWR | O_CREAT);&lt;br /&gt;
 &lt;br /&gt;
 	write(file, &amp;quot;Hello&amp;quot;, 5);&lt;br /&gt;
 &lt;br /&gt;
 	//Could also use lseek() to do this&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	write(file, &amp;quot;world\n&amp;quot;, 6);&lt;br /&gt;
 &lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	close(file);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 2.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 { &lt;br /&gt;
 	int blockSize = atoi(argv[1]);&lt;br /&gt;
 	char *inFile = argv[2];&lt;br /&gt;
 	char *outFile = argv[3];&lt;br /&gt;
 	int buf;&lt;br /&gt;
 	FILE *readF = fopen(inFile, &amp;quot;r&amp;quot;);&lt;br /&gt;
 	FILE *writeF = fopen(outFile, &amp;quot;w&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 	//Get file size&lt;br /&gt;
 	fseek(readF, 0, SEEK_END);&lt;br /&gt;
 	int inSize = ftell(readF);&lt;br /&gt;
 	rewind(readF);&lt;br /&gt;
 &lt;br /&gt;
 	buf = getc(readF);&lt;br /&gt;
 	while(buf!=EOF){&lt;br /&gt;
 		putc(buf, writeF);&lt;br /&gt;
 		buf = getc(readF);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	printf(&amp;quot;File copy complete. Need to pad.\n&amp;quot;);&lt;br /&gt;
 	&lt;br /&gt;
 	//get output filesize&lt;br /&gt;
 	int outSize = ftell(writeF);&lt;br /&gt;
 	&lt;br /&gt;
 	int remainder = outSize % blockSize;&lt;br /&gt;
 	int pad = blockSize - remainder;&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0;i&amp;lt;pad;i++){&lt;br /&gt;
 		putc(0, writeF);&lt;br /&gt;
 	}&lt;br /&gt;
 &lt;br /&gt;
 	fclose(readF);&lt;br /&gt;
 	fclose(writeF);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17484</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17484"/>
		<updated>2012-10-24T15:31:44Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
#See code.&lt;br /&gt;
#See code.&lt;br /&gt;
#Loopback mounts could be useful to mount the VM filesystem on the hosts physical disk as a block device.  To be able to do this, the VM software must use the same format for its filesystem as the host&#039;s physical disk, or block device.&lt;br /&gt;
&lt;br /&gt;
 1.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 {&lt;br /&gt;
 	int file = open(&amp;quot;helloworld&amp;quot;, O_RDWR | O_CREAT);&lt;br /&gt;
 &lt;br /&gt;
 	write(file, &amp;quot;Hello&amp;quot;, 5);&lt;br /&gt;
 &lt;br /&gt;
 	//Could also use lseek() to do this&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	write(file, &amp;quot;world\n&amp;quot;, 6);&lt;br /&gt;
 &lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	close(file);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 2.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 { &lt;br /&gt;
 	int blockSize = atoi(argv[1]);&lt;br /&gt;
 	char *inFile = argv[2];&lt;br /&gt;
 	char *outFile = argv[3];&lt;br /&gt;
 	int buf;&lt;br /&gt;
 	FILE *readF = fopen(inFile, &amp;quot;r&amp;quot;);&lt;br /&gt;
 	FILE *writeF = fopen(outFile, &amp;quot;w&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 	//Get file size&lt;br /&gt;
 	fseek(readF, 0, SEEK_END);&lt;br /&gt;
 	int inSize = ftell(readF);&lt;br /&gt;
 	rewind(readF);&lt;br /&gt;
 &lt;br /&gt;
 	buf = getc(readF);&lt;br /&gt;
 	while(buf!=EOF){&lt;br /&gt;
 		putc(buf, writeF);&lt;br /&gt;
 		buf = getc(readF);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	printf(&amp;quot;File copy complete. Need to pad.\n&amp;quot;);&lt;br /&gt;
 	&lt;br /&gt;
 	//get output filesize&lt;br /&gt;
 	int outSize = ftell(writeF);&lt;br /&gt;
 	&lt;br /&gt;
 	int remainder = outSize % blockSize;&lt;br /&gt;
 	int pad = blockSize - remainder;&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0;i&amp;lt;pad;i++){&lt;br /&gt;
 		putc(0, writeF);&lt;br /&gt;
 	}&lt;br /&gt;
 	outSize = ftell(writeF);&lt;br /&gt;
 	printf(&amp;quot;%d\n&amp;quot;, outSize%blockSize); &lt;br /&gt;
 &lt;br /&gt;
 	fclose(readF);&lt;br /&gt;
 	fclose(writeF);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17483</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17483"/>
		<updated>2012-10-24T15:31:24Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
#See code.&lt;br /&gt;
#See code.&lt;br /&gt;
#Loopback mounts could be useful to mount the VM filesystem on the hosts physical disk as a block device.  To be able to do this, the VM software must use the same format for its filesystem as the host&#039;s physical disk, or block device.&lt;br /&gt;
&lt;br /&gt;
 1.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 {&lt;br /&gt;
 	int file = open(&amp;quot;helloworld&amp;quot;, O_RDWR | O_CREAT);&lt;br /&gt;
 &lt;br /&gt;
 	write(file, &amp;quot;Hello&amp;quot;, 5);&lt;br /&gt;
 &lt;br /&gt;
 	//Could also use lseek() to do this&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	write(file, &amp;quot;world\n&amp;quot;, 6);&lt;br /&gt;
 &lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	close(file);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
 2.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;sys/types.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;sys/stat.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;unistd.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 { &lt;br /&gt;
 	int blockSize = atoi(argv[1]);&lt;br /&gt;
 	char *inFile = argv[2];&lt;br /&gt;
 	char *outFile = argv[3];&lt;br /&gt;
 	&lt;br /&gt;
 	//char *buf;	&lt;br /&gt;
 	int buf;&lt;br /&gt;
&lt;br /&gt;
 	FILE *readF = fopen(inFile, &amp;quot;r&amp;quot;);&lt;br /&gt;
 	FILE *writeF = fopen(outFile, &amp;quot;w&amp;quot;);&lt;br /&gt;
 &lt;br /&gt;
 	//Get file size&lt;br /&gt;
 	fseek(readF, 0, SEEK_END);&lt;br /&gt;
 	int inSize = ftell(readF);&lt;br /&gt;
 	rewind(readF);&lt;br /&gt;
 &lt;br /&gt;
 	buf = getc(readF);&lt;br /&gt;
 	while(buf!=EOF){&lt;br /&gt;
 		putc(buf, writeF);&lt;br /&gt;
 		buf = getc(readF);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	printf(&amp;quot;File copy complete. Need to pad.\n&amp;quot;);&lt;br /&gt;
 	&lt;br /&gt;
 	//get output filesize&lt;br /&gt;
 	int outSize = ftell(writeF);&lt;br /&gt;
 	&lt;br /&gt;
 	int remainder = outSize % blockSize;&lt;br /&gt;
 	int pad = blockSize - remainder;&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0;i&amp;lt;pad;i++){&lt;br /&gt;
 		putc(0, writeF);&lt;br /&gt;
 	}&lt;br /&gt;
 	outSize = ftell(writeF);&lt;br /&gt;
 	printf(&amp;quot;%d\n&amp;quot;, outSize%blockSize); &lt;br /&gt;
 &lt;br /&gt;
 	fclose(readF);&lt;br /&gt;
 	fclose(writeF);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17482</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17482"/>
		<updated>2012-10-24T15:29:15Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
#See code.&lt;br /&gt;
#See code.&lt;br /&gt;
#Loopback mounts could be useful to mount the VM filesystem on the hosts physical disk as a block device.  To be able to do this, the VM software must use the same format for its filesystem as the host&#039;s physical disk, or block device.&lt;br /&gt;
&lt;br /&gt;
 1.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 {&lt;br /&gt;
 	int file = open(&amp;quot;helloworld&amp;quot;, O_RDWR | O_CREAT);&lt;br /&gt;
 &lt;br /&gt;
 	write(file, &amp;quot;Hello&amp;quot;, 5);&lt;br /&gt;
 &lt;br /&gt;
 	//Could also use lseek() to do this&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	write(file, &amp;quot;world\n&amp;quot;, 6);&lt;br /&gt;
 &lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	close(file);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17481</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17481"/>
		<updated>2012-10-24T15:29:01Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
#See code.&lt;br /&gt;
#See code.&lt;br /&gt;
#Loopback mounts could be useful to mount the VM filesystem on the hosts physical disk as a block device.  To be able to do this, the VM software must use the same format for its filesystem as the host&#039;s physical disk, or block device.&lt;br /&gt;
&lt;br /&gt;
 1.&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 #include &amp;lt;fcntl.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 int main(int argc, char *argv[])&lt;br /&gt;
 {&lt;br /&gt;
 	int file = open(&amp;quot;helloworld&amp;quot;, O_RDWR | O_CREAT);&lt;br /&gt;
 &lt;br /&gt;
 	write(file, &amp;quot;Hello&amp;quot;, 5);&lt;br /&gt;
 &lt;br /&gt;
 	//Could also use lseek() to do this&lt;br /&gt;
 	int i;&lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	write(file, &amp;quot;world\n&amp;quot;, 6);&lt;br /&gt;
 &lt;br /&gt;
 	for(i=0; i&amp;lt;1000; i++)&lt;br /&gt;
 	{&lt;br /&gt;
 		write(file, &amp;quot;\0&amp;quot;, 1);&lt;br /&gt;
 	}&lt;br /&gt;
 	&lt;br /&gt;
 	close(file);&lt;br /&gt;
 	return 0;&lt;br /&gt;
 }&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17479</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17479"/>
		<updated>2012-10-24T15:27:36Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
#See code.&lt;br /&gt;
#See code.&lt;br /&gt;
#Loopback mounts could be useful to mount the VM filesystem on the hosts physical disk as a block device.  To be able to do this, the VM software must use the same format for its filesystem as the host&#039;s physical disk, or block device.&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17478</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17478"/>
		<updated>2012-10-24T15:26:59Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
#See code.&lt;br /&gt;
#See code.&lt;br /&gt;
#Loopback mounts could be useful to mount the VM filesystem on the hosts physical disk as a block device.  To be able to do this, the VM software must use the same format for its filesystem as the host&#039;s physical disk, or block device.&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17458</id>
		<title>COMP 3000 Lab 4 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_4_2012&amp;diff=17458"/>
		<updated>2012-10-23T16:09:17Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;A few guidelines:&lt;br /&gt;
* Submit your solutions for both Part A and Part B via cuLearn by Friday, October 19th at 11:55 pm.  There are 32 points.&lt;br /&gt;
* Please answer using a single text file (with a .txt extension). Do not submit doc, docx, pdf, or other formats.  Also, please do not submit an archive (zip, tarball, rar) of multiple text files, just upload one.  &#039;&#039;&#039;Anything other than a single text file will receive no credit.&#039;&#039;&#039;&lt;br /&gt;
* Show all your work.  Short answers are not sufficient; you should list any websites or individuals you consult and should document any experiments you conducted.  For any question that you could just answer without any external reference or experiment, write &amp;quot;(no work required)&amp;quot; after your answer.&lt;br /&gt;
* All submitted code and commands should compile and run. Partial code fragments or explanations may not be given credit.  While code may use standard C and UNIX/Linux libraries, no code should rely on external binaries.&lt;br /&gt;
* &#039;&#039;&#039;The exercises in this lab require root access on a Linux system.&#039;&#039;&#039;  In the labs, you can use the COMP2401-2404 VM with the admin account (password &amp;quot;nimda1234!&amp;quot;).  To get a root shell (rather than having to type sudo for each command, run &amp;lt;tt&amp;gt;sudo su &amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
Be sure to do the following questions in order.&lt;br /&gt;
&lt;br /&gt;
# [2] Run the command &amp;lt;tt&amp;gt;truncate -s 1G foo&amp;lt;/tt&amp;gt;.  What is the logical size of foo, and how much space does it consume on disk?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;mkfs.ext4 foo&amp;lt;/tt&amp;gt;.  (Say &amp;quot;yes&amp;quot; to operating on a regular file.)  What is the logical size of foo now, and how much space does it now consume on disk?&lt;br /&gt;
# [1] What command do you run to check the filesystem in foo for errors?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;df&amp;lt;/tt&amp;gt;.  What device is mounted on /mnt?  What is this device?&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;rsync -a -v /etc /mnt&amp;lt;/tt&amp;gt;.  What does this command do?  Explain the arguments as well.&lt;br /&gt;
# [2] Run &amp;lt;tt&amp;gt;umount /mnt&amp;lt;/tt&amp;gt;.  What files can you still access, and what have gone away?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;dd if=/dev/zero of=foo conv=notrunc count=10 bs=512&amp;lt;/tt&amp;gt;.  What does this command do?&lt;br /&gt;
# [1] Run &amp;lt;tt&amp;gt;mount foo /mnt&amp;lt;/tt&amp;gt;.  What error do you get?&lt;br /&gt;
# [2] What command can you run to make foo mountable again?  What characteristic of the file system enables this command to work?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [6] Create a simple C program to generate a file consisting of the word &amp;quot;Hello&amp;quot;, one thousand bytes of blank space (null bytes), and then &amp;quot;world\n&amp;quot;, and then another thousand null bytes, such that the file produced consumes the maximum amount of space given its contents.&lt;br /&gt;
# [6] Create a C program &amp;quot;mycopy-blocks.c&amp;quot; that takes three arguments: a block size and two filenames A and B as command line arguments.  This program should copy the contents of A to B, making B a byte-for-byte copy of A, except that the length of B should be evenly divisible by the block size.  The file should be padded with nulls as necessary.  Zero bytes in A should consume little to no space in B, however, including the padding.&lt;br /&gt;
# [4] How could loopback mounts be useful when working with virtual machines?  What conditions must the VM software meet for this to work?&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
#The logical size of the file is 1GB, but it consumes 0 space on disk.  Can use ls -s to find the disk usage.&lt;br /&gt;
#The logical size has remained the same at 1GB, but it now consumes 33MB on disk. Can use ls -s to find the disk usage and can multiply the size of the blocks by the block count to get the size.  Can use sudo tune2fs -l &amp;lt;file with filesystem&amp;gt; to get block info.&lt;br /&gt;
#fsck.ext4 foo&lt;br /&gt;
#This will mount the foo filesystem on the /mnt directory.&lt;br /&gt;
#/dev/loop0 is mounted on /mnt.  It allows a file to be accessed as if it were a block device.&lt;br /&gt;
#rsync is a fast and versatile file copying tool. It uses incremental copies to improve speed, only copying files not present in the destination that are present in the source and only sending file changes rather than entire files.  With respect to the command rsync -a -v /etc /mnt, rsync will be executed locally and will copy the contents of the /etc directory to /mnt.  It will do this with increased verbosity (-v) and in archive mode (-a), ensuring that symbolic links, devices, attributes, permissions, ownerships etc are preserved.  It will also leave files present in the destination that are not present in the source.  To delete these you must specify with --delete --force.&lt;br /&gt;
#By executing umount /mnt, all access to the files via /mnt has been lost.&lt;br /&gt;
#This command copies 10 blocks, 512 bytes at a time, from /dev/zero to foo.  It is essentially destroying the first blocks of data in foo, corrupting the filesystem.&lt;br /&gt;
#&amp;quot;mount: you must specify the filesystem type.&amp;quot;&lt;br /&gt;
#Can use fsck.ext4 to make foo mountable again.  This is possible due to the redundant copies of the superblock that were created when foo was made a filesystem.  (The previous command &amp;quot;dd&amp;quot; effectively destroyed the main superblock of foo)&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2012&amp;diff=17430</id>
		<title>COMP 3000 Lab 2 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2012&amp;diff=17430"/>
		<updated>2012-10-16T14:46:05Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Instructions===&lt;br /&gt;
&lt;br /&gt;
In this lab you will examine how Ubuntu Linux initializes itself.&lt;br /&gt;
&lt;br /&gt;
You should expect to complete Part A in tutorial.  You should submit the answers to both Part A and Part B, however, on Friday.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Indicate where you got the information to answer each question.&#039;&#039;&#039;  This can be as simple as &amp;quot;the TA told me&amp;quot; or instead &amp;quot;I looked at chapter 7 in book X&amp;quot; or, just, &amp;quot;man page for ls&amp;quot;.  If you do not include such information, you&#039;ll automatically have &#039;&#039;&#039;10 points&#039;&#039;&#039; deducted from your grade.&lt;br /&gt;
&lt;br /&gt;
You should turn in Lab 2 by 10 PM on Friday, September 28 via [https://www.carleton.ca/culearn/ cuLearn].  Your answers should be in &#039;&#039;&#039;plain text&#039;&#039;&#039; (the true UNIX file format) or &#039;&#039;&#039;PDF&#039;&#039;&#039;.  No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format).  This lab has 40 points in total (and 5 bonus points).&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
The [http://upstart.ubuntu.com/cookbook/ Upstart cookbook] covers most aspects of Upstart, the SystemV init script replacement used by Ubuntu.&lt;br /&gt;
Also, you may want to look at the following commands: &amp;lt;tt&amp;gt;ps, top, gnome-system-monitor, service, kill, pstree, dpkg, apt-get&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running Ubuntu in Lab===&lt;br /&gt;
&lt;br /&gt;
You will need to do this assignment on an Ubuntu 12.04 machine that you have root access to.  Generally this will be a virtual machine.  In the labs, you can access pre-made Ubuntu virtual machines in VirtualBox.  Note that these are for other courses; we, however, can use them as well as we just need a standard Ubuntu install.&lt;br /&gt;
&lt;br /&gt;
To access the VMs open virtualbox, start menu, apps, virtualbox folder, virtualbox, it should be listed when you start the program.  You can use the following accounts for the COMP2401-2404 IMAGE only!  Note that only the &#039;&#039;&#039;admin&#039;&#039;&#039; account has root access.&lt;br /&gt;
* Username: &#039;&#039;&#039;student&#039;&#039;&#039;  Password: &#039;&#039;tneduts!&#039;&#039;&lt;br /&gt;
* Username: &#039;&#039;&#039;admin&#039;&#039;&#039;  Password: &#039;&#039;nimda1234!&#039;&#039;&lt;br /&gt;
* Username: &#039;&#039;&#039;Starbuck&#039;&#039;&#039;  Password: &#039;&#039;harbinger&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
# [2] How can you get a list of all of the processes running on the system from the command line?  Please give the command and required arguments, if any.&lt;br /&gt;
# [10] What are five processes that are running on your system as non-regular users (i.e., as users other than the one you logged in as)?  What does each do, briefly?  Note: please exclude all processes enclosed in [], as those are built in to the kernel.&lt;br /&gt;
# [1] How can I restart the graphical login screen on Ubuntu?  (Hint: use virtual terminals and Ctrl-Alt-F? combinations to access a terminal that is independent of the GUI.  Also, make sure you are aren&#039;t logged into a graphical session when you try this!)&lt;br /&gt;
# [2] What happens when you send a kill -9 signal to one of the &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt; processes that are running by default?  Why?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [2] What starts the upstart daemon?  When is it started?&lt;br /&gt;
# [2] How would you &amp;quot;change the system runlevel&amp;quot; to reboot?  Shut down?&lt;br /&gt;
# [2] Look at the output of &amp;lt;tt&amp;gt;ls -l /etc/init.d/&amp;lt;/tt&amp;gt;.  You will note &amp;lt;tt&amp;gt;-&amp;gt;&amp;lt;/tt&amp;gt; for many of the entries.  This arrow shows that those entries are symbolic links.  Where do most of these symbolic links point to?  Why?&lt;br /&gt;
# [2] Install the &amp;lt;tt&amp;gt;openssh-server&amp;lt;/tt&amp;gt; package in your virtual machine  from the command line.  What command(s) did you use?&lt;br /&gt;
# [2] Note that &amp;lt;tt&amp;gt;sshd&amp;lt;/tt&amp;gt; has separate entries in &amp;lt;tt&amp;gt;/etc/init&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;/etc/init.d&amp;lt;/tt&amp;gt; differ.  Why do both exist (when most services have either one or the other)?&lt;br /&gt;
# [8] Log messages for the system are stored in &amp;lt;tt&amp;gt;/var/log&amp;lt;/tt&amp;gt;.  What are four log files that are present on your system?  (Ignore the ones with numeric extensions, those are old versions.)  What program wrote each of those files directly?&lt;br /&gt;
# [4] In &amp;lt;tt&amp;gt;/etc/init.d/ssh&amp;lt;/tt&amp;gt; there are two lines near the beginning that end with &amp;lt;tt&amp;gt;output || exit 0&amp;lt;/tt&amp;gt; (should be lines 16 and 17).  What do each of these lines do exactly?  And what is there purpose?&lt;br /&gt;
# [2] What are the equivalent lines, if any, to these &amp;lt;tt&amp;gt;|| exit 0&amp;lt;/tt&amp;gt; lines in &amp;lt;tt&amp;gt;/etc/init/ssh&amp;lt;/tt&amp;gt;?&lt;br /&gt;
# [1] What is plymouth?&lt;br /&gt;
# &#039;&#039;&#039;BONUS: &#039;&#039;&#039; [5] Trace plymouth&#039;s behavior throughout the boot process.&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
&lt;br /&gt;
# ps -aux&amp;lt;br/&amp;gt;ps -e&amp;lt;br/&amp;gt;Among others.&lt;br /&gt;
# cron - Cron is the time-based job scheduler.&amp;lt;br/&amp;gt;lightdm - Display manager. It also manages the X servers and facilitates remote logins using the XDMCP protocol.&amp;lt;br/&amp;gt;Network Manager - NetworkManager is a set of co-operative tools that make networking simple and straightforward. Whether WiFi, wired, 3G, or Bluetooth, NetworkManager allows you to quickly move from one network to another user/sbin/modemmanager.&amp;lt;br/&amp;gt;Upstart Socket Bridge - The  upstart-socket-bridge queries the Upstart init(8) daemon for all job configurations which start on or stop on the socket event. It  then waits  for  an incoming connection on each specified socket(7) and when detected emits the socket event (socket-event (7)), setting a number of environment variables for the job to query.&amp;lt;br/&amp;gt;acpid - The acpid process is designed to notify user-space programs of ACPI events.&amp;lt;br/&amp;gt;These are just some examples of acceptable answers.  There are others as well.&lt;br /&gt;
# Make sure you are not logged into xsession, then restart lightdm with sudo service lightdm restart&lt;br /&gt;
# It will automatically respawn itself.  There is a line in the tty script that instructs the process to automatically restart in the case of failure or termination of the process.&lt;br /&gt;
&lt;br /&gt;
Part B&lt;br /&gt;
&lt;br /&gt;
# The kernel starts the upstart daemon at system boot.&lt;br /&gt;
# To reboot use either telinit 6 or shutdown -r.  To shutdown use either telinit 0 or shutdown tool with -h option and a time.&lt;br /&gt;
# The links point to /lib/init/upstart-job.  Ubuntu is transitioning from SysVinit scripts to upstart scripts, these links are used to redirect to the upstart services.&lt;br /&gt;
# sudo apt-get install openssh-server.&lt;br /&gt;
# The init.d script is used only for chroot environments.  See lines 14-26 in init.d/ssh script.&lt;br /&gt;
# Can check syslog process to see which logs it directly writes too.  Some acceptable answers are:&lt;br /&gt;
## auth.log - CRON, lightdm, polkitd&lt;br /&gt;
## boot.log - modem-manager&lt;br /&gt;
## bootstrap.log - gpgv, dpkg&lt;br /&gt;
## dpkg.log - dpkg&lt;br /&gt;
## fontconfig.log - fontconfig&lt;br /&gt;
## kern.log - kernel&lt;br /&gt;
## pm-powersave.log - powerd&lt;br /&gt;
## pm-suspend.log - sleepd&lt;br /&gt;
## ufw.log - ufw&lt;br /&gt;
# test -x /usr/sbin/sshd || exit 0 - Check whether &amp;quot;/usr/sbin/sshd&amp;quot; exists and is executable and exit with status of 0 if not.  Used to verify SSHD is installed.&amp;lt;br/&amp;gt;( /usr/sbin/sshd -\? 2&amp;gt;&amp;amp;1 | grep -q OpenSSH ) 2&amp;gt;/dev/null || exit 0 - Runs SSH script with illegal option and pipes the output to grep to check for OpenSSH.  Rest is piped to /dev/null essentially discarding it.  This line checks to verify that the version of SSH installed is OpenSSH.  If not will exit with status of 0.&lt;br /&gt;
# test -x /usr/sbin/sshd || { stop; exit 0; }&amp;lt;br/&amp;gt;Does not have a check for OpenSSH.&lt;br /&gt;
# Plymouth is a bootsplash. It provides a graphical boot animation while the boot process takes place in the background.&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2012&amp;diff=17429</id>
		<title>COMP 3000 Lab 2 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2012&amp;diff=17429"/>
		<updated>2012-10-16T14:33:06Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Instructions===&lt;br /&gt;
&lt;br /&gt;
In this lab you will examine how Ubuntu Linux initializes itself.&lt;br /&gt;
&lt;br /&gt;
You should expect to complete Part A in tutorial.  You should submit the answers to both Part A and Part B, however, on Friday.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Indicate where you got the information to answer each question.&#039;&#039;&#039;  This can be as simple as &amp;quot;the TA told me&amp;quot; or instead &amp;quot;I looked at chapter 7 in book X&amp;quot; or, just, &amp;quot;man page for ls&amp;quot;.  If you do not include such information, you&#039;ll automatically have &#039;&#039;&#039;10 points&#039;&#039;&#039; deducted from your grade.&lt;br /&gt;
&lt;br /&gt;
You should turn in Lab 2 by 10 PM on Friday, September 28 via [https://www.carleton.ca/culearn/ cuLearn].  Your answers should be in &#039;&#039;&#039;plain text&#039;&#039;&#039; (the true UNIX file format) or &#039;&#039;&#039;PDF&#039;&#039;&#039;.  No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format).  This lab has 40 points in total (and 5 bonus points).&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
The [http://upstart.ubuntu.com/cookbook/ Upstart cookbook] covers most aspects of Upstart, the SystemV init script replacement used by Ubuntu.&lt;br /&gt;
Also, you may want to look at the following commands: &amp;lt;tt&amp;gt;ps, top, gnome-system-monitor, service, kill, pstree, dpkg, apt-get&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running Ubuntu in Lab===&lt;br /&gt;
&lt;br /&gt;
You will need to do this assignment on an Ubuntu 12.04 machine that you have root access to.  Generally this will be a virtual machine.  In the labs, you can access pre-made Ubuntu virtual machines in VirtualBox.  Note that these are for other courses; we, however, can use them as well as we just need a standard Ubuntu install.&lt;br /&gt;
&lt;br /&gt;
To access the VMs open virtualbox, start menu, apps, virtualbox folder, virtualbox, it should be listed when you start the program.  You can use the following accounts for the COMP2401-2404 IMAGE only!  Note that only the &#039;&#039;&#039;admin&#039;&#039;&#039; account has root access.&lt;br /&gt;
* Username: &#039;&#039;&#039;student&#039;&#039;&#039;  Password: &#039;&#039;tneduts!&#039;&#039;&lt;br /&gt;
* Username: &#039;&#039;&#039;admin&#039;&#039;&#039;  Password: &#039;&#039;nimda1234!&#039;&#039;&lt;br /&gt;
* Username: &#039;&#039;&#039;Starbuck&#039;&#039;&#039;  Password: &#039;&#039;harbinger&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
# [2] How can you get a list of all of the processes running on the system from the command line?  Please give the command and required arguments, if any.&lt;br /&gt;
# [10] What are five processes that are running on your system as non-regular users (i.e., as users other than the one you logged in as)?  What does each do, briefly?  Note: please exclude all processes enclosed in [], as those are built in to the kernel.&lt;br /&gt;
# [1] How can I restart the graphical login screen on Ubuntu?  (Hint: use virtual terminals and Ctrl-Alt-F? combinations to access a terminal that is independent of the GUI.  Also, make sure you are aren&#039;t logged into a graphical session when you try this!)&lt;br /&gt;
# [2] What happens when you send a kill -9 signal to one of the &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt; processes that are running by default?  Why?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [2] What starts the upstart daemon?  When is it started?&lt;br /&gt;
# [2] How would you &amp;quot;change the system runlevel&amp;quot; to reboot?  Shut down?&lt;br /&gt;
# [2] Look at the output of &amp;lt;tt&amp;gt;ls -l /etc/init.d/&amp;lt;/tt&amp;gt;.  You will note &amp;lt;tt&amp;gt;-&amp;gt;&amp;lt;/tt&amp;gt; for many of the entries.  This arrow shows that those entries are symbolic links.  Where do most of these symbolic links point to?  Why?&lt;br /&gt;
# [2] Install the &amp;lt;tt&amp;gt;openssh-server&amp;lt;/tt&amp;gt; package in your virtual machine  from the command line.  What command(s) did you use?&lt;br /&gt;
# [2] Note that &amp;lt;tt&amp;gt;sshd&amp;lt;/tt&amp;gt; has separate entries in &amp;lt;tt&amp;gt;/etc/init&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;/etc/init.d&amp;lt;/tt&amp;gt; differ.  Why do both exist (when most services have either one or the other)?&lt;br /&gt;
# [8] Log messages for the system are stored in &amp;lt;tt&amp;gt;/var/log&amp;lt;/tt&amp;gt;.  What are four log files that are present on your system?  (Ignore the ones with numeric extensions, those are old versions.)  What program wrote each of those files directly?&lt;br /&gt;
# [4] In &amp;lt;tt&amp;gt;/etc/init.d/ssh&amp;lt;/tt&amp;gt; there are two lines near the beginning that end with &amp;lt;tt&amp;gt;output || exit 0&amp;lt;/tt&amp;gt; (should be lines 16 and 17).  What do each of these lines do exactly?  And what is there purpose?&lt;br /&gt;
# [2] What are the equivalent lines, if any, to these &amp;lt;tt&amp;gt;|| exit 0&amp;lt;/tt&amp;gt; lines in &amp;lt;tt&amp;gt;/etc/init/ssh&amp;lt;/tt&amp;gt;?&lt;br /&gt;
# [1] What is plymouth?&lt;br /&gt;
# &#039;&#039;&#039;BONUS: &#039;&#039;&#039; [5] Trace plymouth&#039;s behavior throughout the boot process.&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
&lt;br /&gt;
1. &lt;br /&gt;
&lt;br /&gt;
ps -aux&lt;br /&gt;
&lt;br /&gt;
ps -e&lt;br /&gt;
&lt;br /&gt;
Among others.&lt;br /&gt;
&lt;br /&gt;
2.&lt;br /&gt;
&lt;br /&gt;
cron&lt;br /&gt;
- Cron is the time-based job scheduler.&lt;br /&gt;
&lt;br /&gt;
lightdm &lt;br /&gt;
- Display manager. It also manages the X servers and facilitates remote logins using the XDMCP protocol.&lt;br /&gt;
&lt;br /&gt;
Network Manager&lt;br /&gt;
- NetworkManager is a set of co-operative tools that make networking simple and straightforward. Whether WiFi, wired, 3G, or Bluetooth, NetworkManager allows you to quickly move from one network to another user/sbin/modemmanager.&lt;br /&gt;
&lt;br /&gt;
Upstart Socket Bridge &lt;br /&gt;
- The  upstart-socket-bridge queries the Upstart init(8) daemon for all job configurations which start on or stop on the socket event. It  then waits  for  an incoming connection on each specified socket(7) and when detected emits the socket event (socket-event (7)), setting a number of environment variables for the job to query.&lt;br /&gt;
&lt;br /&gt;
acpid&lt;br /&gt;
- The acpid process is designed to notify user-space programs of ACPI events.&lt;br /&gt;
These are just some examples of acceptable answers.  There are others as well.&lt;br /&gt;
&lt;br /&gt;
3.&lt;br /&gt;
Make sure you are not logged into xsession, then restart lightdm with sudo service lightdm restart&lt;br /&gt;
&lt;br /&gt;
4.&lt;br /&gt;
It will automatically respawn itself.  There is a line in the tty script that instructs the process to automatically restart in the case of failure or termination of the process.&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2012&amp;diff=17428</id>
		<title>COMP 3000 Lab 2 2012</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=COMP_3000_Lab_2_2012&amp;diff=17428"/>
		<updated>2012-10-16T14:28:50Z</updated>

		<summary type="html">&lt;p&gt;Jbeltram: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;===Instructions===&lt;br /&gt;
&lt;br /&gt;
In this lab you will examine how Ubuntu Linux initializes itself.&lt;br /&gt;
&lt;br /&gt;
You should expect to complete Part A in tutorial.  You should submit the answers to both Part A and Part B, however, on Friday.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;Indicate where you got the information to answer each question.&#039;&#039;&#039;  This can be as simple as &amp;quot;the TA told me&amp;quot; or instead &amp;quot;I looked at chapter 7 in book X&amp;quot; or, just, &amp;quot;man page for ls&amp;quot;.  If you do not include such information, you&#039;ll automatically have &#039;&#039;&#039;10 points&#039;&#039;&#039; deducted from your grade.&lt;br /&gt;
&lt;br /&gt;
You should turn in Lab 2 by 10 PM on Friday, September 28 via [https://www.carleton.ca/culearn/ cuLearn].  Your answers should be in &#039;&#039;&#039;plain text&#039;&#039;&#039; (the true UNIX file format) or &#039;&#039;&#039;PDF&#039;&#039;&#039;.  No other formats are acceptable (and will result in a zero grade until re-submitted in the correct format).  This lab has 40 points in total (and 5 bonus points).&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
&lt;br /&gt;
The [http://upstart.ubuntu.com/cookbook/ Upstart cookbook] covers most aspects of Upstart, the SystemV init script replacement used by Ubuntu.&lt;br /&gt;
Also, you may want to look at the following commands: &amp;lt;tt&amp;gt;ps, top, gnome-system-monitor, service, kill, pstree, dpkg, apt-get&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Running Ubuntu in Lab===&lt;br /&gt;
&lt;br /&gt;
You will need to do this assignment on an Ubuntu 12.04 machine that you have root access to.  Generally this will be a virtual machine.  In the labs, you can access pre-made Ubuntu virtual machines in VirtualBox.  Note that these are for other courses; we, however, can use them as well as we just need a standard Ubuntu install.&lt;br /&gt;
&lt;br /&gt;
To access the VMs open virtualbox, start menu, apps, virtualbox folder, virtualbox, it should be listed when you start the program.  You can use the following accounts for the COMP2401-2404 IMAGE only!  Note that only the &#039;&#039;&#039;admin&#039;&#039;&#039; account has root access.&lt;br /&gt;
* Username: &#039;&#039;&#039;student&#039;&#039;&#039;  Password: &#039;&#039;tneduts!&#039;&#039;&lt;br /&gt;
* Username: &#039;&#039;&#039;admin&#039;&#039;&#039;  Password: &#039;&#039;nimda1234!&#039;&#039;&lt;br /&gt;
* Username: &#039;&#039;&#039;Starbuck&#039;&#039;&#039;  Password: &#039;&#039;harbinger&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
==Part A==&lt;br /&gt;
# [2] How can you get a list of all of the processes running on the system from the command line?  Please give the command and required arguments, if any.&lt;br /&gt;
# [10] What are five processes that are running on your system as non-regular users (i.e., as users other than the one you logged in as)?  What does each do, briefly?  Note: please exclude all processes enclosed in [], as those are built in to the kernel.&lt;br /&gt;
# [1] How can I restart the graphical login screen on Ubuntu?  (Hint: use virtual terminals and Ctrl-Alt-F? combinations to access a terminal that is independent of the GUI.  Also, make sure you are aren&#039;t logged into a graphical session when you try this!)&lt;br /&gt;
# [2] What happens when you send a kill -9 signal to one of the &amp;lt;tt&amp;gt;getty&amp;lt;/tt&amp;gt; processes that are running by default?  Why?&lt;br /&gt;
&lt;br /&gt;
==Part B==&lt;br /&gt;
# [2] What starts the upstart daemon?  When is it started?&lt;br /&gt;
# [2] How would you &amp;quot;change the system runlevel&amp;quot; to reboot?  Shut down?&lt;br /&gt;
# [2] Look at the output of &amp;lt;tt&amp;gt;ls -l /etc/init.d/&amp;lt;/tt&amp;gt;.  You will note &amp;lt;tt&amp;gt;-&amp;gt;&amp;lt;/tt&amp;gt; for many of the entries.  This arrow shows that those entries are symbolic links.  Where do most of these symbolic links point to?  Why?&lt;br /&gt;
# [2] Install the &amp;lt;tt&amp;gt;openssh-server&amp;lt;/tt&amp;gt; package in your virtual machine  from the command line.  What command(s) did you use?&lt;br /&gt;
# [2] Note that &amp;lt;tt&amp;gt;sshd&amp;lt;/tt&amp;gt; has separate entries in &amp;lt;tt&amp;gt;/etc/init&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;/etc/init.d&amp;lt;/tt&amp;gt; differ.  Why do both exist (when most services have either one or the other)?&lt;br /&gt;
# [8] Log messages for the system are stored in &amp;lt;tt&amp;gt;/var/log&amp;lt;/tt&amp;gt;.  What are four log files that are present on your system?  (Ignore the ones with numeric extensions, those are old versions.)  What program wrote each of those files directly?&lt;br /&gt;
# [4] In &amp;lt;tt&amp;gt;/etc/init.d/ssh&amp;lt;/tt&amp;gt; there are two lines near the beginning that end with &amp;lt;tt&amp;gt;output || exit 0&amp;lt;/tt&amp;gt; (should be lines 16 and 17).  What do each of these lines do exactly?  And what is there purpose?&lt;br /&gt;
# [2] What are the equivalent lines, if any, to these &amp;lt;tt&amp;gt;|| exit 0&amp;lt;/tt&amp;gt; lines in &amp;lt;tt&amp;gt;/etc/init/ssh&amp;lt;/tt&amp;gt;?&lt;br /&gt;
# [1] What is plymouth?&lt;br /&gt;
# &#039;&#039;&#039;BONUS: &#039;&#039;&#039; [5] Trace plymouth&#039;s behavior throughout the boot process.&lt;br /&gt;
&lt;br /&gt;
==Answers==&lt;br /&gt;
Part A&lt;br /&gt;
1. &lt;br /&gt;
ps -aux&lt;br /&gt;
ps -e&lt;br /&gt;
Among others.&lt;br /&gt;
&lt;br /&gt;
2. &lt;br /&gt;
cron&lt;br /&gt;
- Cron is the time-based job scheduler.&lt;br /&gt;
lightdm &lt;br /&gt;
- Display manager. It also manages the X servers and facilitates remote logins using the XDMCP protocol.&lt;br /&gt;
Network Manager&lt;br /&gt;
- NetworkManager is a set of co-operative tools that make networking simple and straightforward. Whether WiFi, wired, 3G, or Bluetooth, NetworkManager allows you to quickly move from one network to another user/sbin/modemmanager.&lt;br /&gt;
Upstart Socket Bridge &lt;br /&gt;
- The  upstart-socket-bridge queries the Upstart init(8) daemon for all job configurations which start on or stop on the socket event. It  then waits  for  an incoming connection on each specified socket(7) and when detected emits the socket event (socket-event (7)), setting a number of environment variables for the job to query.&lt;br /&gt;
acpid&lt;br /&gt;
- The acpid process is designed to notify user-space programs of ACPI events.&lt;br /&gt;
These are just some examples of acceptable answers.  There are others as well.&lt;br /&gt;
&lt;br /&gt;
3. Make sure you are not logged into xsession, then restart lightdm with sudo service lightdm restart&lt;br /&gt;
&lt;br /&gt;
4. It will automatically respawn itself.  There is a line in the tty script that instructs the process to automatically restart in the case of failure or termination of the process.&lt;/div&gt;</summary>
		<author><name>Jbeltram</name></author>
	</entry>
</feed>