COMP3000 Operating Systems W22: Tutorial 3: Difference between revisions

From Soma-notes
mNo edit summary
mNo edit summary
Line 1: Line 1:
In this tutorial, you will be experimenting with and extending [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w22/tut3/3000shell.c 3000shell.c], a proof-of-concept program to show you how a Linux shell works. Also, you will be learning to read and modify C code, which prepares you for subsequent tutorials and assignments.
In this tutorial, you will be experimenting with and extending [https://people.scs.carleton.ca/~lianyingzhao/comp3000/w22/tut3/3000shell.c 3000shell.c], a proof-of-concept program to show you how a Linux shell works. Also, you will be learning to read and modify C code, which prepares you for subsequent tutorials and assignments.


'''Make sure you use the original code from 3000shell for each question.'''
'''Make sure you use the original code from 3000shell for each question/task.'''


Tutorials are graded based on participation and effort ('''so no need to try to have the “correct” answers — what matters is the process'''), but you should still turn in your work. Submit your answers on Brightspace as a single text file named "<username>-comp3000-t3.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Tutorial 3", your name, student number, and the date of submission.  
Tutorials are graded based on participation and effort ('''so no need to try to have the “correct” answers — what matters is the process'''), but you should still turn in your work. Submit your answers on Brightspace as a single text file named "<username>-comp3000-t3.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Tutorial 3", your name, student number, and the date of submission.  
Line 10: Line 10:


You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.
You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.
==Background==
===Processes===
Each application running on a system is assigned a unique process identifier (PID). The <tt>ps</tt> command shows the process identifiers for running processes. Each process running on the system is kept separated from other processes by the operating system.
When you enter a command at a shell prompt, most of the time you are creating a new process which runs the program you specified.
===Controlling Processes===
On Linux, once the processes have been created, you can control them by sending them signals. You send signals when you type certain key sequences in most shells: Control-C sends INT (interrupt), Control-Z sends STOP.
You can send a signal to a process using the kill command:
kill -<signal> <process ID>
So, to stop process 4542, type:
kill -STOP 4542
By default, <tt>kill</tt> sends the <tt>TERM</tt> signal.
Each signal has both a string name (e.g., <tt>STOP</tt>) and a numeric form (e.g., 19 correspondingly). See the full list of signals with <tt>kill -l</tt>.
===Standard input/output, Shell and Terminal===
Recall that the shell is a command interpreter (program). In comparison, a terminal is a device used to enter data into and display/printing data from a computer. It used to be physical, hence we call the virtual ones today pseudoterminal. In this context, we refer to it as pts -- pseudo teletypes, e.g., <tt>/dev/pts/1</tt> (just the slave side. Those who are curious can refer to <tt>man ptmx</tt>).
The standard output (e.g., <tt>/dev/stdout</tt>), input (e.g., <tt>/dev/stdin</tt>) and error (<tt>/dev/stderr</tt>) are just symbolic endpoints in any programs (of which the shell is an example), that can be redirected anywhere, where output goes, input comes and error is reported.
So, in summary, you connect to a terminal to interact with a computer, by running a shell to receive your commands, which redirects standard in/out/err to the terminal.

Revision as of 05:10, 20 January 2022

In this tutorial, you will be experimenting with and extending 3000shell.c, a proof-of-concept program to show you how a Linux shell works. Also, you will be learning to read and modify C code, which prepares you for subsequent tutorials and assignments.

Make sure you use the original code from 3000shell for each question/task.

Tutorials are graded based on participation and effort (so no need to try to have the “correct” answers — what matters is the process), but you should still turn in your work. Submit your answers on Brightspace as a single text file named "<username>-comp3000-t3.txt" (where username is your MyCarletonOne username). The first four lines of this file should be "COMP 3000 Tutorial 3", your name, student number, and the date of submission.

The deadline is usually four days after the tutorial date (see the actual deadline on the submission entry). Note that the submission entry is enforced by the system, so you may fail to get the effort marks even if it is one minute past the deadline.

You should also check in with your assigned TA online (by responding to the poll in the Teams channel tutorials-public or the private channel). Your TA will be your first point of contact when you have questions or encounter any issues during the tutorial session.

You get 1.5 marks for submitting answers that shows your effort and 0.5 for checking in, making this tutorial worth 2 points total.

Background

Processes

Each application running on a system is assigned a unique process identifier (PID). The ps command shows the process identifiers for running processes. Each process running on the system is kept separated from other processes by the operating system.

When you enter a command at a shell prompt, most of the time you are creating a new process which runs the program you specified.

Controlling Processes

On Linux, once the processes have been created, you can control them by sending them signals. You send signals when you type certain key sequences in most shells: Control-C sends INT (interrupt), Control-Z sends STOP.

You can send a signal to a process using the kill command:

kill -<signal> <process ID>

So, to stop process 4542, type:

kill -STOP 4542

By default, kill sends the TERM signal.

Each signal has both a string name (e.g., STOP) and a numeric form (e.g., 19 correspondingly). See the full list of signals with kill -l.

Standard input/output, Shell and Terminal

Recall that the shell is a command interpreter (program). In comparison, a terminal is a device used to enter data into and display/printing data from a computer. It used to be physical, hence we call the virtual ones today pseudoterminal. In this context, we refer to it as pts -- pseudo teletypes, e.g., /dev/pts/1 (just the slave side. Those who are curious can refer to man ptmx).

The standard output (e.g., /dev/stdout), input (e.g., /dev/stdin) and error (/dev/stderr) are just symbolic endpoints in any programs (of which the shell is an example), that can be redirected anywhere, where output goes, input comes and error is reported.

So, in summary, you connect to a terminal to interact with a computer, by running a shell to receive your commands, which redirects standard in/out/err to the terminal.