0% found this document useful (0 votes)
15 views15 pages

OS2 - Week 10 - Week11

This document outlines a lab exercise for managing processes in a Linux operating system environment. It includes tasks for starting, stopping, and manipulating processes using commands like 'cat', 'jobs', 'top', 'kill', and 'pkill'. The lab aims to teach students about process control and resource management within the operating system.

Uploaded by

salshehri9522
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views15 pages

OS2 - Week 10 - Week11

This document outlines a lab exercise for managing processes in a Linux operating system environment. It includes tasks for starting, stopping, and manipulating processes using commands like 'cat', 'jobs', 'top', 'kill', and 'pkill'. The lab aims to teach students about process control and resource management within the operating system.

Uploaded by

salshehri9522
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

‫المملكـــــــة العربيــــة السعوديـــــة‬

KINGDOM OF SAUDI ARABIA


‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs

Week 5 – Lab 1
Part 1: Managing Processes
Processes carry out tasks within the operating system. A process can be thought of as a computer
program in action. During the lifetime of a process it will use many system resources. It will use the
CPUs in the system to run its instructions and the system's physical memory to hold it and its data.
It will open and use files within the filesystems and may directly or indirectly use the physical
devices in the system. Linux must keep track of the process itself and of the system resources that it
has so that it can manage it and the other processes in the system fairly. It would not be fair to the
other processes in the system if one process monopolized most of the system's physical memory or
its CPUs.

In these tasks you will start and stop processes. Now open the terminal application and complete the
following tasks

1. From the terminal, type the following command:

cat /dev/zero > /dev/null

Your output should be similar to the following:

{{{{{{{{{[[[[{{{{{

This command is used to read the contents of the /dev/zero file (which consists of zeros) and
redirect the output to the /dev/null file (which is commonly known as the bit bucket). In
reality it is a "nonsense" command to execute; it is used here to demonstrate process control.

Notice that the terminal appears to hang up at this command. This is due to running this
command in the “foreground”. The system will continue to cat the file until the process is
terminated or suspended by the user.

2. To terminate a foreground process, press Ctrl-c. To suspend (pause) the process, type Ctrl-z.

Designed by Aiman Alobadi 1 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs

3. Next, to start the same process in the background, type:

cat /dev/zero > /dev/null &

Your output should be similar to the following:

By adding the ampersand (&) to the end of the command, the process is started in the
background allowing the user to maintain control of the terminal.

An easier way to enter the above command would be to take advantage of the
command history. You could have pressed the up arrow key on the keyboard, add
a space and & to the end of the command and then pressed the Enter key.
This is a time-saver when entering similar commands.

Notice that the previous command returns the following information: [1] 158

This means that this process has a job number of 1 (as demonstrated by the output of [1]) and a
Process ID (PID) of 158. Each terminal/shell will have unique job numbers. The PID is system-
wide; each process has a unique ID number.

This information is important when performing certain process manipulations, such as stopping
processes or changing their priority value.

Note: Your Process ID will likely be different than the one in the example.

4. To see which commands are running in the current terminal, type the following command:

jobs

Your output should be similar to the following:

Designed by Aiman Alobadi 2 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


5. Next, start another cat command in the background by typing the following:

cat /dev/zero > /dev/null &

Your output should be similar to the following:

Notice the different job number and process ID for this new command.

6. Now, there should be two cat commands running in the background. To verify, issue the jobs
command again:

jobs

Your output should be similar to the following:

7. Once you have verified that two cat commands are running, bring the first command to the
foreground by typing the following:

fg %1

Your output should be similar to the following:

8. Notice that, once again, the cat command has taken control of the terminal. To suspend (pause)
the process and regain control of the terminal, press

Ctrl-z

Designed by Aiman Alobadi 3 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


9. To have this process continue executing in the background, execute the following command:

bg %1

Your output should be similar to the following:

10. Issue the jobs command again to verify two running processes :

jobs

Your output should be similar to the following:

11. Next, start one more cat command by typing the following:

cat /dev/zero > /dev/null &

Your output should be similar to the following:

12. Issue the jobs command again to verify three running processes :

jobs

Designed by Aiman Alobadi 4 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs

13. Using the job number, stop the last cat command with the kill command and verify it was
stopped executing the jobs command:

kill %3
jobs

Your output should be similar to the following:

14. Finally, you can stop all of the cat commands with the killall command. After executing the
killall command, wait a few moments, and then run the jobs command to verify that all
processes have stopped:

killall cat
jobs

Your output should be similar to the following:

Part 2: Use Top to View Processes


In these tasks, you will use the top command to work with processes. By default the top program
sorts the processes in descending order of percentage of CPU usage, so the busiest programs will be
at the top of its listing. Now open the terminal application and complete the following tasks

Now open the terminal application and complete the following tasks

Designed by Aiman Alobadi 5 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


1. From the terminal window, type the following commands:

cat /dev/zero > /dev/null &


cat /dev/zero > /dev/null &

Your output should be similar to the following:

Make note of the PIDs on your system for the above commands! They will be
different than the examples that we are providing.

2. Next, start the top command by typing the following in the terminal:

top

Your output should be similar to the following:

Note: The output of the top command changes every 2 seconds.

Designed by Aiman Alobadi 6 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


3. The top command is an interactive program, which means that you can issue commands within
the program. You will use the top command to kill the cat processes. Type the letter k (notice
that the prompt appears underneath Swap).

4. At the pid to signal/kill: prompt, type the PID of the first running cat process, then press
Enter. Notice that the prompt changes as below:

5. At the Send pid # signal [15/sigterm]: prompt, press the Enter key. Notice that the first cat
command is removed and only one cat command remains in the listing (you may need to wait a
few seconds as the top command refreshes):

Designed by Aiman Alobadi 7 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs

Note: There are several different numeric values that can be sent to a process. These are
predefined values, each with a different meaning. If you want to learn more about these values,
type man kill in a terminal window.

6. Next, kill the remaining cat process as before, this time, at the Kill PID with signal [15]:
prompt, type the letter k followed by the PID of the cat process, use a value of 9 instead of
accepting the default of 15. Press Enter to accept then entry.

The "kill" signal 9 is a "forceful" signal that cannot be ignored unlike the default value of 15.
Notice that all references to the cat command are now removed from top.

7. Type q to exit the top command. The following screen reflects that both cat commands were
terminated:

Part 3: Use pkill and kill To Terminate Processes


In these tasks, we will continue to work with processes. You will use pkill and kill to terminate
processes.

Designed by Aiman Alobadi 8 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


Now open the terminal application and complete the following tasks:

1. To begin, type the following commands in the terminal:

sleep 888888 &


sleep 888888 &

Your output should be similar to the following:

The sleep command is typically used to pause a program (shell script) for a specific period of
time. In this case it is used just to provide a command that will take a long time to run.

Make sure to note the PIDs on your system of the sleep processes for the next
steps! Your PIDs will be different than those demonstrated in the lab.

2. Next, determine which jobs are currently running by typing:

jobs

Your output should be similar to the following:

3. Now, use the kill command to stop the first instance of the sleep command by typing the
following (substitute PID with the process id of your first sleep command). Also, execute jobs
to verify the process has been stopped:

kill PID
jobs

Your output should be similar to the following:

Designed by Aiman Alobadi 9 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs

Helpful Hint: If you can't remember the PID of the first process, just type the
ps (process) command, as shown above.

4. Next, use the pkill command to terminate the remaining sleep command, using the name of
the program rather than the PID:

pkill -15 sleep

Your output should be similar to the following:

Part 4: Using ps to Select and Sort Processes

The ps command can be used to view processes. By default, the ps command will only display the
processes running in the current shell.

Now open the terminal application and complete the following tasks

1. Start up a background process using cat and view current processes using the ps command:

cat /dev/zero > /dev/null &


ps

Your output should be similar to the following:

Designed by Aiman Alobadi 10 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs

2. Execute the ps command using the option -e, so all processes are displayed.

ps -e

Your output should be similar to the following:

Due to this environment being a virtualized operating system, there are far fewer processes than
what would normally be shown with Linux running directly on hardware.

3. Use the ps command with the -o option to specify which columns to output.

ps -o pid,tty,time,%cpu,cmd

Your output should be similar to the following:

Designed by Aiman Alobadi 11 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


4. Use the --sort option to specify which column(s) to sort by. By default, a column specified for
sorting will be in ascending order, this can be forced with placing a plus + symbol in front of the
column name. To specify a descending sort, use the minus - symbol in front of the column
name.

Sort the output of ps by %mem:

ps -o pid,tty,time,%mem,cmd --sort %mem

Your output should be similar to the following:

5. While the ps command can show the percentage of memory that a process is using, the free
command will show overall system memory usage:

free

Your output should be similar to the following:

6. Stop the cat command with the following kill command and verify with the jobs command:

kill 170
jobs

Your output should be similar to the following:

Designed by Aiman Alobadi 12 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs

Week 5 – Lab 2
Package Management
Package management is a system by which software can be installed, updated, queried or removed
from a filesystem. In Linux, there are many different software package management systems, but
the two most popular are those from Debian and Red Hat.

The Linux Standards Base, which is a Linux Foundation project, is designed to specify (through a
consensus) a set of standards that increase the compatibility between conforming Linux systems.
According to the Linux Standards Base, the standard package management system is RPM.

RPM makes use of an ".rpm" file for each software package. This system is what Red Hat-derived
distributions (like Red Hat, Centos, and Fedora) use to manage software. In addition, several other
distributions that are not Red Hat-derived (such as SUSE, OpenSUSE and Mandriva) also use
RPM.

Before start you need to create a directory in the as follow:

cd /etc/yum.repos.d/
mkdir old

Now copy all the files to old directory:

cp * old/

Part1: Setting Up Your Own Repository


In this exercise, you’ll learn how to set up your own repository and mark it as a repository. First
you’ll copy all of the RPM fi les from the Red Hat installation DVD to a directory that you’ll create
on disk. Next you’ll install and run the createrepo package and its dependencies. This package is
used to create the metadata that yum uses while installing the software packages. While installing
the createrepo package, you’ll see that some dependency problems have to be handled as well.

1. Create a directory that you can use as a repository in the root of your server’s file system:

mkdir /repo

2. Insert the Red Hat installation DVD in the optical drive of your server. Assuming that
you run the server in graphical mode, the DVD will be mounted automatically.

Designed by Aiman Alobadi 13 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


3. Go into Packages directory that is stored on the mounted DVD using the command cd:

cd /media/CentOS_6.6_Final/Packages/

4. Copy all the packages files to /repo directory you just created, you don't need the DVD
anymore when this is finished :

cp –v * /repo

5. Go into /repo directory using cd:

cd /repo

6. Now try to install the createrepo package using the following command

rpm –ivh createrepo[Tab]

This doesn’t work, and it gives you a “ Failed dependencies” error. To install createrepo, you
first need to install the deltarpm and python-deltarpm packages.

7. Now install the deltarpm and python-deltarpm packages using the following command:

rpm –ivh deltarpm python-deltarpm

8. Now to install the createrepo package.


9. Once the createrepo package has been installed, use the following command:

createrepo /repo

this will creates the metadata that allows you to use the /repo directory as a repository. This will
take a few minutes. When this procedure is finished, your repository is ready for use.

Part2: Working with yum


In this exercise, you’ll start by using some yum commands, which are explained in the next section
of this chapter. The purpose of using these commands is that at the start of this exercise, yum
doesn’t show anything. Next you’ll enable the repository that you created in the preceding exercise,
and you’ll repeat the yum commands. You will see that after enabling the repositories, the yum
commands now work.

1. Use the command

yum repolist

In its output (repolist: 0), the command tells you that currently no repositories are configured.

Designed by Aiman Alobadi 14 / 15


‫المملكـــــــة العربيــــة السعوديـــــة‬
KINGDOM OF SAUDI ARABIA
‫المؤسسة العامة للتدريب التقني والمهني‬
Technical and Vocational Training Corporation
College of Telecommunications & Electronics – Jeddah
‫كلية االتصاالت واإللكترونيات بجدة‬
Department of Computer Technology
‫قسم تقنية الحاسب‬

Operating System – 2 Labs


2. Use the command

yum search nmap

The result of this command is the message "No Matches found".

3. Now use nano to create a fi le with the name /etc/yum.repos.d/myrepo.repo. Note that
it is important that the fi le has the extension .repo. Without it, yum will completely ignore it!
The file should have the following contents:

[myrepo]
name=myrepo
baseurl=file:///repo
gpgcheck=0

4. Now use the commands yum repolist and yum search nmap again.

Part3: Installing, removing and update packages with yum


For installing application packages we use the command yum install package_name. And for
removing installed application we use the command yum remove package_name.

1. Lets install nmap package using the following command:

yum install nmap

2. Now remove nmap package using the following command:

yum remove nmap

3. To update all installed packages we use the command:

yum update

4. To update specific package we add the packge name after the update command, for example:

yum update nmap

Designed by Aiman Alobadi 15 / 15

You might also like