Programming Question

https://csc-knu.github.io/sys-prog/books/Andrew%20…

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

QUESTION 1:

Page 259, Problem 45:

Explain the difference between internal fragmentation and external fragmentation. Which one occurs in paging systems? Which one occurs in systems using pure segmentation?

QUESTION 2:

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper

Page 254, Problems 7:

Using the page table of Fig. 3-9, give the physical address corresponding to each of the following virtual addresses:

(a) 20; (b) 4100; (c) 8300

QUESTION 3:

Based on what you have learned above, please answer the questions below.

Note: Please complete Lab 3 before answering the following questions:

Please provide a single “find” command that displays all the files, excluding directories, that have been changed in the last 7 days under your home directory:

Please provide a single “grep” command that counts how many lines in file /etc/hosts that contains “199”:

Please provide a single “uniq” command that compares the first 3 characters of lines in file /etc/hosts and then displays the number of occurrences of lines in the file:

Please provide a single “grep” command that displays all the lines in all the files, under your home directory, that contain a word “Metropolitan”:

Please provide a single “find” command that searches your home directory and all its subdirectories for the files with an extension “.class” and delete them with confirmations:

QUESTION 4:

Please follow the steps introduced in lab 3 to update your index.html file. Add the links of the websites you found in your Homework 1. Please try all links and make sure all of them work properly CFS264 ‐ Computer and Operating Systems Fundamentals II
Page 1 of 9
Handout 3 – Pico Editor, Compilers, and Linux Utilities
_____________________________________________________________________________________
Following the steps introduced in Handout1 to log onto the host sp-cfsics.metrostate.edu, then try the content
discussed below. Please create a directory lab3 for the following exercises.
Part I: Pico Editor






The pico screen editor was originally designed for the users to edit messages within an email program called
“pine”. With the respect to “pine”, “pico” stands for “pine composer”.
pico also means “small”. For instance, one trillion picoseconds make one second.
pico has a limited number of commands and rules.
pico can be used separately from “pine”. In other words, pico can be used by itself.
pico was adapted from a version of “emacs” called “micro emacs”.
“emacs” is a screen editor itself but it is more complicated and bigger than “pico”.
Format 1: invoke pico with a file name
$ cd
$ mkdir lab3
$ cd lab3
$ pico test2
this is a test.
^x
y
$
Note: ^x means CTRL-x, and y and are responses to the screen prompts, not part of the file.
$ cat test2
this is a test.
$
Format 2: invoke pico without a file name
$ pico
this is a second test.
^x
test3
$
Note: ^x means CTRL-x, and test3 and s are responses to the screen prompts, not part of the file.
$ cat test3
this is a second test.
$

The basic commands of pico are provided in the following table.
Command
Function
Delete a single character backward
The same as key
^K
Delete the current line or marked text
^R
Read in a file
^T
Spell checker
^U
Undelete last text deleted by ^K
^X
Save a file to the disk
_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II
Page 2 of 9
Handout 3 – Pico Editor, Compilers, and Linux Utilities
_____________________________________________________________________________________

Using pico to edit your homepage file “index.html”. Your homepage folder is ~/public_html
$ cd ~/public_html
$ pico index.html
Since the file “index.html” exists, you are going to see the following information on your screen:
Welcome to Metropolitan State University
Please update the file according to the following information (html documents are not case-sensitive):
CFS 264 Computer and Operating Systems Fundamentals II
Metropolitan State University
This web site is still under the construction. Please send your comments to
put your name here
.
Here are my five favorite links for learning Operating Systems:
Operating Systems: Three
Easy Pieces by Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau
To check on your homepage, follow the instructions below:
▪ Invoke either MS Internet Explorer or any other web browser
▪ Check on the following URL:
http://sp-cfsics.metrostate.edu/~cfs264su20xx

If the web page does not work properly, please modify it accordingly. Otherwise, please print out
the page and hand it in before you leave.
Part II: The Compilers
▪ Learn how to run a Java, C or C++ program on Linux. At the prompt “$”, please do the following:
$ cd ~/lab3
Java:

Please create the following file using pico with a file name as “Greeting.java”.
public class Greeting
{
public static void main(String[] args)
{
System.out.println(“Hello, CFS 264 Class!”);
}
}
_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II
Page 3 of 9
Handout 3 – Pico Editor, Compilers, and Linux Utilities
_____________________________________________________________________________________

After you create the file above, at the prompt “$”, please follow the steps below:
$ javac Greeting.java
$ java Greeting
Hello, CFS 264 Class!
$
Notes:
▪ If you see some syntax errors, you should use pico to correct them accordingly and then rerun the programs
as shown above
▪ A concise pico tutorial can be found at: https://www.ssc.wisc.edu/sscc/pubs/7-15.pdf
C

Please create the following file with a file name as “myfirst.c”.
#include
int main ()
{
printf(“Hello, Metropolitan State University!\n”);
}

After you create the file above, at the prompt “ $”, please do the following:
$ gcc myfirst.c
$ ./a.out
Hello, Metropolitan State University!
$
$ gcc -o myfirst myfirst.c
$ ./myfirst
Hello, Metropolitan State University!
$
C++

Please create the following file with a file name as “firstcpp.cc”.
#include
int main()
{
std::cout test2
CLASS
1234
3456
Ctrl-D
$ cat > test3
clasS
1234
1234
Ctrl-D

Search for the word “Class” in file test1
$ grep Class test1
Class

Search for the word “Class” in file test1 with option “i”:
$ grep -i Class test1
Class
ClasS
_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II
Page 6 of 9
Handout 3 – Pico Editor, Compilers, and Linux Utilities
_____________________________________________________________________________________

Search for the word “Class” in file test1 with option “n”:
$ grep -n Class test1
1:Class

Search for the word “Class” in file test1 with option “c”:
$ grep -c Class test1
1

Search for the word “Class” in file test1 with option “ni”:
$ grep -ni Class test1
1:Class
3:ClasS

Search for the word “Class” in files test1, test2, and test3 with option “i”:
$ grep -in Class test?
test1:1:Class
test1:3:ClasS
test2:1:CLASS
test3:1:clasS

Search for the word “Class” in files test1, test2, and test3 with options “i”and “c”:
$ grep -ic Class test?
test1:2
test2:1
test3:1

Search for the word “Ethernet” from command ifconfig with options “w” (search by whole word):
$ ifconfig | grep -w “Ethernet”
eth0
Link encap:Ethernet HWaddr 00:50:56:bd:04:9a
sort





Allows one to sort a file into alphabetical or numerical order.
By default, the output is printed on the screen in an ascending order..
The file is sorted on a line-by-line basis.
If two lines are identical, it does not matter which line is placed in front of another.
sort frequently-used options
b
Ignores the leading blanks (tabs and space characters).
d
Sorts the file in dictionary order;
Only letters, digits, and spaces or tabs are used with the sorting;
Ignores punctuation and control characters.
f
Ignores the distinction between lowercase and uppercase characters;
All characters are treated as uppercase characters.
m
Merge already sorted lists.
n
Sorts numbers by their arithmetic values rather than by their first digit.
o
Writes the output to a specified file.
r
Sorts the file in a descending order.
Examples:
▪ Create a file called “testsort” as follow:
$ cat > testsort
Four
fourteen
4
_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II
Page 7 of 9
Handout 3 – Pico Editor, Compilers, and Linux Utilities
_____________________________________________________________________________________
14
Ctrl-D

Sort the file “testsort” in an ascending order (or dictionary order as option “d”):
$ sort testsort
14
4
Four
fourteen
$ sort –d testsort
14
4
Four
fourteen

Sort the file “testsort” in a descending order:
$ sort -r testsort
fourteen
Four
4
14

Sort the file “testsort” by their arithmetic values rather than by their first digit or letter:
$ sort -n testsort
Four
fourteen
4
14

Sort the file “testsort” in a descending order and output it to a file called “testsort.descending”:
$ sort -r -o testsort.descending testsort
$ cat testsort.descending
fourteen
Four
4
14

Sort the file “testsort” in a descending order and output it to a file called “a2”:
$ sort testsort > a2
$ cat a2
14
4
Four
fourteen

Merge two already sorted lists, a2 and a3, as follow:
$ cat > a3
0
22
8
ABC
^D
$ sort -m a2 a3
0
14
22
4
8
ABC
Four
fourteen
uniq

Removing duplicated lines from a file.
_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II
Page 8 of 9
Handout 3 – Pico Editor, Compilers, and Linux Utilities
_____________________________________________________________________________________

Format:
uniq options [inputfile [outputfile] ]
uniq frequently-used options
c
Precede each output line by the number of times it occur.
d
Display the repeated lines.
u
Display the lines that are not repeated.

Examples:
$ cat test3
clasS
1234
1234

Displays the number of times a line is repeated:
$ uniq -c test3
1 clasS
2 1234

Displays the lines with no duplicates:
$ uniq -u test3
clasS

Displays the lines that have duplicates:
$ uniq -d test3
1234

Only compare the first n characters in lines:
$ cat > test4
1234
1234
12345
123456
^D
$ uniq test4
1234
12345
123456
$ uniq –-check-chars=5 test4
1234
12345
wc


Counts numbers of lines, words, and characters in a file
Format:
wc options filename
wc frequently-used options
c
print the byte counts
m
print the character counts
l
print the newline counts
L
print the length of the longest line
w
print the word counts
_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
CFS264 ‐ Computer and Operating Systems Fundamentals II
Page 9 of 9
Handout 3 – Pico Editor, Compilers, and Linux Utilities
_____________________________________________________________________________________

Examples:
▪ Create a file called testwc as follow
$ cat > testwc
line 1
line 2
line 3
line 4
testing
CTRL-D

Display all information about testwc:
$ wc testwc
5 9 36 testwc

Display the number of lines in testwc
$ wc -l testwc
5 testwc

Display the number of words in testwc
$ wc -w testwc
9 testwc

Display the number of characters in testwc with “c” option
$ wc -c testwc
36 testwc

Display the number of characters in testwc with “m” option
$ wc -m testwc
36 testwc

Display the length of the longest line in testwc
$ wc -L testwc
7 testwc
_____________________________________________________________________________________________
Please complete the Linux Lab in D2L
1
Programming Question
Name
Institution
Course
Professor
Date
2
Programming Question
Question 1: What is the difference between timesharing and multiprogramming systems?
Timesharing Systems
Timesharing systems are operating systems capable of allowing concurrent interaction among
several users with a computer. The main focus of a timesharing system is to provide users with a
quick response. The system shares both CPU time and system resources with potentially many
users, switching between them very quickly to give the impression that the user has their own
machine. Frequent context switching achieves this by saving and restoring a process state,
enabling multiple processes to share a single CPU.
Multiprogramming Systems
Multiprogramming systems require a reasonable level of CPU utilization. More than one
program can reside in memory at a time, and the operating system can allocate the CPU to the
various programs in turn. The CPU can switch from one to another to ensure that, while one is
waiting for some I/O activity to complete, another can be using the CPU. The primary objective
is to keep the CPU busy at all times by arranging jobs to ensure they are available for execution
on the CPU.
Question 2: What is the difference between kernel and user mode? Explain how having two
distinct modes aids in designing an operating system.
Kernel Mode
Kernel mode is a class privilege mode. It is the CPU mode in which the operating system has
free rein over the hardware and can execute, literally, any CPU instruction. This is because the
OS can execute privileged instructions, access hardware directly, and perform memory
3
management. The operating system uses it for the most critical and sensitive tasks, such as
managing processes, memory, and hardware devices.
User Mode
User mode is a restricted CPU operation mode in which applications operate with fewer rights.
Executing in user mode, programs are unable to access the hardware directly or execute
privileged instructions; in contrast, they have to make system calls to request the services of the
operating system. This was the primary restriction on user programs from directly interfacing
with critical parts of the OS or hardware.
How Having Two Distinct Modes Aids in Designing an Operating System
These two different modes are very useful in designing an operating system. First, it provides an
extra level of system security because any user application running in user mode cannot get
direct access to critical or sensitive kernel operating system functions. Secondly, it improves
system stability by preventing errors or crashes in user mode from disrupting the overall system
integrity, as it lacks direct access to critical system resources. Thirdly, the kernel facilitates
managed resource access by stepping in between all hardware requests, enabling the OS to
manage and allocate resources efficiently and fairly. Finally, such a separation enhances the
modularity of the high-level OS design since it makes an easily understandable difference
between application-level operations and system-level functions in a way that will simplify the
maintenance, debugging, and enhancements of the operating system.
Question 3: OS and Linux Tutorial Websites
Operating Systems Learning Websites
Website 1

Title: Operating Systems: Three Easy Pieces.
4

URL: http://pages.cs.wisc.edu/~remzi/OSTEP/

Author/Organization
Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau

Last Updated: 2023.

Overall Impression
This site provides a comprehensive and accessible introduction to operating system
concepts through the free online book “Operating Systems: Three Easy Pieces.”
Evaluation

One Thing Learned: General concept of how operating systems handle memory.

Example: Through clear examples, the book makes topics and concepts understandable to
the reader, including how paging and segmentation work.

Next Learning Topic: Detailed workings of synchronization primitives like murexes and
semaphores.

Most Interesting: Clarity and structure of explanations that work to demystify complex
OS concepts.
Website 2:

Title: GeeksforGeeks Operating Systems Tutorial

URL: https://www.geeksforgeeks.org/operating-systems/

Author/Organization: GeeksforGeeks

Last Updated: 25 Jan, 2024.

Overall Impression: This site offers a wide array of tutorials on operating systems
concepts, from basic to advanced topics, in an easy-to-understand manner.
Evaluation
5

One Thing Learned: CPU scheduling algorithms.

Example: Example defining step by step the round robin scheduling.

Next Learning Topic: More insights into deadlock prevention and recovery mechanisms.

Most Interesting: The diversity of articles and practical examples that help in a better
understanding.
Linux Learning Websites
Website 1:

Title: Linux Journey

URL: https://linuxjourney.com/

Author/Organization: Independent contributions.

Last Updated: 2023.

Overall Impression: This site is an excellent resource for beginners, providing a
structured path to learning Linux from the ground up.
Evaluation:

One Thing Learned: Basic operations on Linux command line.

Example: Introduction to file system navigation commands, [ls, cd, pwd].

Upcoming Topic to Learn: Advanced Shell Scripting Techniques.

Most Amusing: The gamified and interactive approach to learning makes it interesting.
Website 2:

Title: The Linux Documentation Project

URL: http://www.tldp.org/

Author/Organization: The Linux Documentation Project.

Last Updated: 2020-08-19.
6

Overall Impression: An extensive collection of Linux documentation, how-tos, and
guides catering to all levels of Linux users.
Evaluation:

One Thing Learned: Advanced configuration of the Linux kernel.

Example: Detailed guide on recompiling the Linux kernel to add or remove specific
features.

Next Learning Topic: Best Practices for running a Linux System.

Most Interesting: The very detail and authoritative documentation which is available
absolutely at free of cost.
Website 3:

Title: Linux Command

URL: https://linuxcommand.org/

Author/Organization: William Shotts.

Last Updated: 2024.

Overall Impression: A user-friendly site focusing on teaching Linux command-line
skills, ideal for beginners.
Evaluation

One Thing Learned: Fundamentals of shell scripting.

Example: A simple shell script example given to carry out tasks like file backups.

Next Learning Topic: Advanced topics in shell scripting and automation.

Most Interesting: Training is done in a straightforward and practical way on commands
and scripting.
7
References
Tanenbaum, A., & Boschung, H. T. (2018). Modern operating systems (4th Edition). Pearson.

Are you stuck with your online class?
Get help from our team of writers!

Order your essay today and save 20% with the discount code RAPID