0% found this document useful (0 votes)
39 views

CSC3300 - Lab Activity 3

This document provides instructions for a lab assignment on process management and system utilities in Linux. It includes tasks on redirecting input/output streams, using pipes to connect commands, managing processes, and using the Vim text editor. Students are asked to complete the tasks, answer questions to demonstrate their understanding, and are encouraged to explore shell scripting further.

Uploaded by

214391
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

CSC3300 - Lab Activity 3

This document provides instructions for a lab assignment on process management and system utilities in Linux. It includes tasks on redirecting input/output streams, using pipes to connect commands, managing processes, and using the Vim text editor. Students are asked to complete the tasks, answer questions to demonstrate their understanding, and are encouraged to explore shell scripting further.

Uploaded by

214391
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

CSC3300 Sem.

1 2023/2024

UNIVERSITI PUTRA MALAYSIA

FAKULTI SAINS KOMPUTER DAN TEKNOLOGI MAKLUMAT

LAB 3

NAME: NUR AISYAH BINTI ZULKIFLY


MATRIC NUMBER: 214391

ASSIGNMENT TITLE : Process Management and System Utilities

ASSIGNMENT TYPE : Individual

INSTRUCTIONS:

1. Redirecting I/O Streams

Task: Using Output Redirection ‘>’ in Linux


The use of the ‘>’ is to send output to file instead of screen (the standard output).
Type the following command, which is to send the output to file named
‘myoutput.txt’

~$ ls > myoutput.txt

Task: Using Output Redirection ‘>>’ in Linux


The use of the ‘>>’ is to send output to file by adding the new content with the
existing content. Type the following command, which adding more content to file
named ‘myoutput.txt’

~$ ls >> myoutput.txt

Task: Using Input Redirection ‘<’ in Linux


The use of the ‘<’ is to set a specified file as the source of input data for a command.
Type the following command, which read the file specified file and display its
content.

~$ ls < myoutput.txt

(Note: The command will be the same as ls myoutput.txt (without the ‘<’), since
the ls command already expecting the first parameter to be the input file.)

1
CSC3300 Sem. 1 2023/2024

Questions:
1. Describe the examples of tasks that might require the use of the redirection
operators (>, >>, <)?
‘>’: Used to send information to a file
‘>>’: Used to send information to the end of the file instead of overwriting it
‘<’: Used to read the input for a command from a file

2. Process Communication Using Pipe

Task: Using Pipe ‘|’ in Linux

The use of pipe ‘|’ is to allow programs to share data (e.g. to allow a program to share
its output to become input for another program/command). Type the following
command which connect ls command with head command,

~$ ls | head -3

The number of pipes can be more than one. Type the following command, which runs
the command ls and send its output as the input for head command, and then send its
output to be the input for tail command.

~$ ls | head -3 | tail -1

2
CSC3300 Sem. 1 2023/2024

Questions:
1. Use man to learn more about the use of ls, head, tail and then describe the
purpose of using the switches (-3 for head, and -1 for tail).

ls Command:
To access the manual page for ls, you can use the following command: man ls.
The ls command is used to list files and directories in a directory.
It has several options, such as -l for a long listing format, -a for displaying hidden
files, and -h for displaying file sizes in a human-readable format.

head Command:
To access the manual page for head, you can use the command: man head.
The head command is used to display the first few lines of a text file.
There are no options like -3 for head. By default, it displays the first 10 lines of
the file.

tail Command:
To access the manual page for tail, you can use the command: man tail.
The tail command is used to display the last few lines of a text file.
There are no options like -1 for tail. By default, it displays the last 10 lines of the
file.

2. Give an example of other instruction that can be used with pipes. Show how you
use it, and describe the objective/purpose.

Suppose you have a directory named text_files with multiple text files, and you
want to find unique words and their occurrences across all these files. You can use
the following command:

cat text_files/*.txt | tr -s '[:space:]' '\n' | sort | uniq -c | sort -nr

 cat text_files/*.txt reads the content of all text files in the text_files
directory and combines them into a single stream.
 tr -s '[:space:]' '\n' replaces spaces and other whitespace characters with
newline characters. This effectively splits the text into individual words.
 sort sorts the words alphabetically.
 uniq -c counts the unique words and their occurrences.
 sort -nr sorts the unique words by their frequency in descending order.

3
CSC3300 Sem. 1 2023/2024

3. Process Management
Task: Creating Process
Create a process by running any program or user application.

Task: Viewing Process List


View the currently running process(es) by using typing the following command,
~$ps

Task: Terminating Process


We may terminate any running processes by using the kill command.
Run a Vim program. Then press Ctrl+Z to make it as background process.

Use the ps command to list the currently running processes. Then use the kill
command to terminate a process by supplying the process’ id. Assuming there is a
Vim process with ID (PID) 2390, signal -9 will caused the program to be terminated
instantly. Type the following command,

~$ kill -9 2390

We may also use the pidof command to determine a known process. For example, we
know a Vim program is running, use the following command to determine the PID of
the program.

~$ pidof vim

Questions:
1. Use man to learn more about the use of kill and then describe the three more
switches (other than -9) that can be used with kill command.
kill – send a signal to a process
Switches:
-l: list signal names. This option has optional argument, which will convert signal
number to signal name, or other way around.
-L: list signal names in a nice table
-s, --signal<signal>: specify the signal to be sent. The signal can be specified by
using name or number.

4
CSC3300 Sem. 1 2023/2024

4. Create and Editing Text File Using Text Editor

Task: Open the Vim editor by typing


~$
vim

Press Ctrl+Z to make it as background process.

Use vimtutor to learn more about Vim (commands for editing file, and also how you
can save and open an existing file).

~$ vimtutor

Learn from the vimtutor. Then recall the Vim with fg command and practice creating
editing and saving text file.

Questions:
1. Specify three Vim commands that you can use in editing
Deletion: Press x to delete the character under the cursor
Insertion: Press i to insert text
Appending: Press A to append text

2. Specify Vim commands that you can use to save a file


Use :wq to save a file and exit

3. Specify Vim commands that you can use to open a file


Shift +:e[file] – Opens a [file] that you want to open

Note: Exploring Shell Scripting

Shell scripting is a powerful facility provided by Bash (and many other shells in other
operating systems). With the experience from the exercise, students are encouraged to
explore features like using variables, branching and looping command provided in Bash’s
shell scripting to produce more advanced process management tasks such as batch
commands, scheduled processing or automatic software installation/setup.

You might also like