cs211 lab1
http://www.maths.nuigalway.ie/~gettrick/teach/cs211/labs/l1.html
-
For this lab you must submit all source code (python
files), and, if applicable, the result(s) of running the program on (a few)
test cases. This should be sent in as a file upload/attachment via BLACKBOARD (not directly by email).
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code). Any questions asked should be answered by
typing the answers into the relevant box on the BLACKBOARD upload form, or
by including the answer in comments in the PYTHON source code..
-
This material should be uploaded
before
the deadline of 10pm
Thursday October 5th., 2017. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated.
You risk getting zero for your lab if it is found to be
plagiarized.
-
Log on to your computer/PC in the normal way. Look for the red
ICON with the label/name NX Client or No Machine. Open this
software, and connect to leas.nuigalway.ie. (LEAS is the main
Linux machine on campus, "Linux Environment for Academic Studies.) Log on to
this machine using your
normal username and password.
-
When you have logged on, there is an icon in the window called Terminal,
click on that to open a command line terminal.
-
Repeat the last step (to open another terminal), the more the merrier!!
-
In one of your terminals, type in xterm&. (This opens yet another
terminal, called an X terminal, it just looks a little different from
the other terminals: The ampersand means to run the command/process in
the background.)
-
Type in mkdir cs211 to make a folder/directory where you will
store your cs211 stuff.
-
Type in cd cs211 to change directory.
-
You may like to make further subdirectories/folders by typing
mkdir labs or mkdir python etc.
-
Familiarize yourself with the ps command, by typing
ps to see what processes you are running, ps -aux
to see all processes on the machine, man ps to see the manual/help
pages for the ps command.
-
TASK 1
Using the command ps -alx, find
(and submit)
the process ID, and corresponding command, of three processes whose parent
process is init() (whose process ID is 1).
-
If you have a PYTHON program - lets say the file name is myfile.py
- in your
current directory (to see current directory, type pwd),
then you can run
the program by typing python myfile.py. Make yourself familiar
with the programs orphanZombie.py and or2.py at
http://www.maths.nuigalway.ie/~gettrick/teach/cs211/progs/, and run them to see what they do.
-
TASK 2
Write (and submit) a PYTHON program where a parent process creates three child processes that
then become orphan processes and live on for at least 20 seconds beyond the
termination of the parent process.
-
TASK 3
Write (and submit) a PYTHON program where a parent process creates a child process
(lets call this child process C), which then in turn creates two child processes
of its own (denoted GC1 and GC1 - from the point of view of the original process,
these are grandchildren). Thereafter in your code, make C turn in to an orphan
process and both GC1 and GC2 turn in to zombie processes, for at least 10
seconds. (You should check your code works by using the top command
to check for the two zombies.)
-
TASK 4
Study the programs pipedemo.py and pipes2.py covered in lectures. Following this, write and submit a PYTHON program with the following behaviour: A parent process creates two child processes; then the first child process reads in some text from the user, and sends it via a pipe to the second chile process: thereafter the second child process reverses all the characters in the string and sends the reversed string back to the first child process (via a second pipe); finally the first chile process prints the reversed string to the screen.
©
NUI, Galway