cs211 lab1
http://www.maths.nuigalway.ie/~gettrick/teach/cs211/
-
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 CANVAS ASSIGNMENT (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 CANVAS upload form, or
by including the answer in comments in the PYTHON source code..
-
This material should be uploaded
before
the deadline of 5pm
Friday February 9th., 2024. 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, chatGPT, fellow students,....)) will not be tolerated.
You risk getting zero for your lab if it is found to be
plagiarized.
-
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 python3 myfile.py. Make yourself familiar
with the programs orphanZombie.py and or2.py at
http://www.maths.nuigalway.ie/~gettrick/teach/cs211/oldNotes/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 GC2 - 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 pipes3.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 child
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 child process prints the reversed string to the screen.
©
University of Galway