<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2015F%3A_Tutorial_4</id>
	<title>Operating Systems 2015F: Tutorial 4 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2015F%3A_Tutorial_4"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2015F:_Tutorial_4&amp;action=history"/>
	<updated>2026-05-01T06:21:51Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2015F:_Tutorial_4&amp;diff=20315&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;In this tutorial you will be learning about concurrency in the filesystem and simple shell scripts.  Run the following three commands in bash.  (Note the \ is just to note the...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2015F:_Tutorial_4&amp;diff=20315&amp;oldid=prev"/>
		<updated>2015-10-09T16:11:28Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;In this tutorial you will be learning about concurrency in the filesystem and simple shell scripts.  Run the following three commands in bash.  (Note the \ is just to note the...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In this tutorial you will be learning about concurrency in the filesystem and simple shell scripts.&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;
# 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;
# 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;
# Approximately how many processes do these two lines generate on your system?  How can you tell?&lt;br /&gt;
# Change each line into a stand-alone shell script with no semicolons.&lt;br /&gt;
# 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;
# Use flock in the shell script versions of the commands to keep the output of the three echo&amp;#039;s in the inner loop from being broken apart (make them &amp;quot;atomic&amp;quot;).  Thus, in race.txt, you&amp;#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&amp;#039;t put race.txt in your home directory on the SCS Linux machines.  Doing this in a VM should work fine.&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>