cs211 lab1
http://maths.nuigalway.ie/~gettrick/teach/cs211/
-
For this lab you must write your own code to execute the tasks below.
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
including the answer in comments in the PYTHON source code...
-
This lab will be graded in the actual lab, face to face. The lab teaching
assistant will ask you to run your code, to explain some lines in your code,
and to explain any output.
You must come in to the lab to get it graded.
-
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
the process ID, and corresponding command, of three processes whose parent
process is init() (whose process ID is 1). (Store that
information in the comments (after the # tag) of one of your
PYTHON files below, so the TA can see it when grading.)
-
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 oZ2.py at
https://maths.nuigalway.ie/~gettrick/teach/cs211/2026/progs/, and run them to see what they do.
-
TASK 2
Write 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 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 pipe3.py
covered in lectures.
Following this, write 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