Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Parallel System Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 25

NATIONAL INSTITUTE OF PUBLIC

ADMINISTRATION

NAME: SIKANYIKA TREYMAX

STUDENT NUMBER: 28026322

PROGRAM: BACHELOR OF SCIENCE IN COMPUTERS

COURSE: PARALLEL SYSTEM

COURSE CODE: 403

YEAR OF STUDY: FOURTH YEAR SEMESTER 2

LECTURE: MRS MOILLY

EMAIL: treymaxsikanyi@gmail.com
QUESTION 1:
Note: For the following questions write the UNIX commands and execute either by
using Cygwin or Linux and attach the screenshots of the output. Only theory answers
will not be counted for the marks

a) When you log in, a program starts executing at your terminal. What is the program
known as?
ANSWER
The Program is known as the shell
b) Name four types of this program that are available on a system?
ANSWER
i. Bash (The boune again shell)
ii. Ksh (The korn shell)
iii. Sh(The bourne Shell)
iv. Csh (The C shell)

c) What is the one thing that is common in directories, devices, terminals and printers?
Everything are treated as file in the Unix including the kernel

d) Name some of the duties of the system administrator that you have encountered in
UNIX programming?
i. Installing and upgrading UNIX system software on campany servers and
computers
ii. Creating UNIX file systems
iii. Setting up and maintaining UNIX user accounts access management
systems
iv. Implementing networks and computer system policies

e) A program file named foo exists in the current directory, but when we try to execute it
by entering foo ,we see message foo : command not found .Explain how that can
happen?
EXPLANATION

Syntax <command><argument/program file>

Foo is an argument not a command . Arguments are not recognized unless they are
used together with command because command are recognized in the unix operating
system for example cat can be used together with fool in order to display the content.
Therefore when you just type fool command not found.

a) Assuming that you are positioned in the directory /home/Romeo, what are these
commands presumed to di and explain whether they will work at all:
(i) cd ../..
(ii) mkdir ../bin
(iii) rmdir ..
(iv) ls ..
Answer
EXPLANATION
1.) Well the first command is used to change directory to parent/root and it goes up one
level .Therefore cd ../.. command is used to change directory to parents parent
directory that is it goes up two levels.
2.) mkdir ../bin definitely this command cannot work reason being that The /bin
Director is a standard subdirectory of the root directory in Unix operating systems that
contains the executable files (i.e., ready to run) unless you are root
3.) rmdir .. this command as well will not worked because the root directories has
content in it so we can’t remove it that is why it is saying the directories is not
empty.
4.) This will definitely work as you can see on the picture it will just list all the contents
of the current directory.
Suppose you have to develop script that refers to a file in Charlie’s home directory. How will
you specify the location of this file in your script to make sure that it works even when
Charlie’s home directory changes?
ANSWER
Charlie uses /usr/Charlie as home directory, and many of his scripts refer to the
pathname/usr/Charlie/html. Later, the home directory is changed to/home/Charlie, thus
breaking all his scripts. How could Charlie have avoided this problem?
The way that Charlie could avoided this problem would have been by adding the
directory “html” to the end of path which in return would have prevented all of his
script from being brocken
b) The command rmdir bar fails with the message that the directory is not empty. On
running ls bar , no files are displayed. Why did the rmdir command fail?

c)

ANSWER

// keep the code Change the name “treysons”

EXPLANATION
The command refuse to delete as it is shown in the image above because the
content inside the bar files are hidden files so if you type ls to check the directory
it will show you nothing but after type the command ls -la which lists everything
including the hidden file .the file shows up as treysons
The second way is to use the command rm -r to delete everything including the
hidden files
d) Run the script command and then issue a few commands before you run exit what do
you see when you run cat -v typescript
f) A files current permission is r w – r – x r - -. Specify the chmod command required to
change them for the following. Using both relative and absolute methods of assigning
permissions
(i) - w-r--r--
(ii) r--r-----
(iii) rwxrwxrwx
(iv) ---------

// keep the code Change the name “treyson”

ANSWER
QUESTION 2:

Note: For the following questions write the UNIX commands and execute either by
using Cygwin or Linux platform and attach the screenshots of the output. Only theory
answers will not be counted for the marks
a) The wc command was designed to count characters, lines and words only in the files.
Explain whether the statement is true or false with a suitable example (write a command
and show with the help of screenshot)
ANSWER
wc - print newline, word, and byte counts for each file .therfore the statement is
TRUE as it is shown on the picture

//change the name wc -m “name”

b) Can you change the system date with date command?

So my conclusion is that you cant change using the date command to change the system
date. It can only show the current time and date

c) Observe the calendar for the year 1752. Do you notice anything unusual? How will
you browse the output of this moving forward and backward as necessary
ANSWER

Yes I have noticed something strange about September some days are missing from 2 to
14th date
Secondly you can output the calender by using the following commands
1.) Cal 1752 | more OR
2.) Cal 1752 | less
Using space or f move one page forward
Using b move one page back
For less
Space or f or z move one page forward
Using b move one page back

d) Convert the decimal number 192 to octal and hexadecimal using


i) bc and
i. printf

which one will you use to display the number in binary ?


d) Run ps , the script command and run ps again . what is the output?
8.You need to accept a secret code through a shell script. What command will you run in the
script to make sure that your keyboard input is not displayed? How do you then revert to the
normal setting?
ANSWER

After writing the script must include the code stty -echo . what this code does is
that it doesn’t allow the terminal t accept the input.

You can revert the settings simply by typing the command stty echo

e) Both your local and remote machines use identical versions of UNIX. How do you
confirm whether you are logged on to a remote machine or not ?
ANSWER
who am i and uname -n command and ENTER will display the logged-in
user name and current tty details. The output of this command contains
the following columns: logged-in user name, tty name, current time with
date and ip-address from where this users initiated the connection.
f) Which of these commands will work? Explain with reasons
(i) mkdir a/b/c
(ii) mkdir a a/b
(iii) rmdir a/b/c
(iv) rmdir a a/b
(v) mkdir /bin/foo

ANSWER

(vi) mkdir a/b/c command will only work only if there is a directory a that
contains a directory b and it exists in the current directory. Then when
the command is run, it will create a new directory c in directory b.
(vii) mkdir a a/b command will only work if the directory ‘a’ does not exist in
the working directory. This command is similar to the following
command_mkdir a, mkdir a/b. This command will create a directory in
the current directory and then b that is sub directory is created inside a.

(viii) rmdir a/b /c just like in(i), rmdir a/b/c command will only work if a
directory ‘a’ exists in the current working directory and also contains
sub- directory b and b further contain subdirectory c. if c is empty this
command will execute otherwise this will result in failure
(ix) rmdir a a/b will always fail. It only functions successfully if the target
directory is empty. Let us assume that the directories a and b exists and b
contained in a. When the command is run, the first part that is rmdir a
will fail as the directory is not empty. If the directory a is empty the first
part will succeed. But after deleting a and b both does not exist, so second
part will fail. Hence the command will fail in any other way.

(x) Mkdir /bin/foo command will run successfully if there exists a directory
bin under te main root directory. And only if the file created is executable
because all the file in the bin directory are all executable. The command
will fail if it already contained a subdirectory named foo

g) A files current permission is r w – r – x r - - . Specify the chmod command required


to change them for the following. Using both relative and absolute methods of
assigning permissions.
i) rwxrwxrwx
ii) r--r-----
iii) ---r--r--
iv) rw--w----

ANSWER
// keep the code Change the name “treysonz”

QUESTION 3:
a) Control hazards can cause a greater performance loss for our MIPS pipeline than do
data hazards. When a branch is executed, it may or may not change the PC to
something other than its current value plus 4. Recall that if a branch changes the PC to
its target address, it is a taken branch; if it falls through, it is not taken, or untaken. If
instruction i is a taken branch, then the PC is normally not changed until the end of
ID, after the completion of the address calculation and comparison.

Consider the pipelined execution of following these instructions:

address40: "beq "$1, $3, 28 # (28 leads to address 72)"


address 44: "and "$12, $2, $5"
address 48: "or "$13, $6, $2"
address 52: "add "$14, $2, $2"
address 72: "lw "$4, 50($7)"

i) Do the above instructions result in branch hazard?

Answer

yes
ii) If so, explain with the help of simplified version of a RISC data path
drawn in pipeline fashion.

answer

If branch condition true, must skip 44, 48, 52


– But, these have already started down the pipeline
– They will complete unless we do something about it
• How do we deal with this?
– We’ll consider 2 possibilities

iii) And also explain how the branch hazard can be resolved? Explain with
branch taken and branch not taken technique

Answer

Dealing w/branch hazards: always stall"

• Branch taken

– Wait 3 cycles"

– No proper instructions in the pipeline"


– Same delay as without stalls (no time lost)"

• Branch not taken

– Still must wait 3 cycles

– Time lost"

– Could have spent CCs fetching, decoding next instructions

Dealing w/branch hazards

• On average, branches are taken ½ the time

– If branch not taken…

• Continue normal processing


– Else, if branch is taken…

• Need to flush improper instruction from pipeline

• One approach:

– Always assume branch will NOT be taken

• Cuts overall time for branch processing in ½

– If prediction is incorrect, just flush the pipeline

QUESTION 4:
Assignment Problem—The Sleeping Teaching Assistant
A university computer science department has a teaching assistant (TA) who helps
undergraduate students with their programming assignments during regular office hours. The
TA’s office is rather small and has room for only one desk with a chair and computer. There
are three chairs in the hallway outside the office where students can sit and wait if the TA is
currently helping another student. When there are no students who need help during office
hours, the TA sits at the desk and takes a nap. If a student arrives during office hours and
finds the TA sleeping, the student must awaken the TA to ask for help. If a student arrives
and finds the TA currently helping another student, the student sits on one of the chairs in the
hallway and waits. If no chairs are available, the student will come back at a later time.

Using POSIX threads, mutex locks, and semaphores, implement a solution that
coordinates the activities of the TA and the students. Details for this assignment
are provided below.

The Students and the TA

Using Pthreads, begin by creating n students. Each will run as a separate thread.
The TA will run as a separate thread as well. Student threads will alternate
between programming for a period of time and seeking help from the TA. If
the TA is
available, they will obtain help. Otherwise, they will either sit in a chair in the
hallway or, if no chairs are available, will resume programming and will seek help
at a later time. If a student arrives and notices that the TA is sleeping, the student
must notify the TA using a semaphore. When the TA finishes helping a student,
the TA must check to see if there are students waiting for help in the hallway. If
so, the TA must help each of these students in turn. If no students are present, the
TA may return to napping.
Perhaps the best option for simulating students programming—as well as the
TA providing help to a student—is to have the appropriate threads sleep for a
random period of time.

POSIX Synchronization

Coverage of POSIX mutex locks and semaphores is provided in Pthread


Synchronization

Required

Write C program for the above given information

Answer
Hangout_1.c

Help_Student
Student_1.c
ta.c
ta.h
Make_file_ 1_2_3_4 file

You might also like