OS 5,6,7,8,9

Ace your homework & exams now with Quizwiz!

if (pid == -1) {

# -1 indicates an error in fork; the new process wasn't created

int status;

# If pid is received and it is positive number

(void)waitpid(pid, &status, 0);

# the parent passes the id to waitpid system call to suspend execution until child

_exit(EXIT_SUCCESS

#Exits using POSIX_exit

else if (pid == 0) {

#Fork was successful and if pid is 0 (which is invalid)

perror("fork failed");

#Prints message that the fork failed

printf("Hello from the child process!\n");

#Prints that it is from child process

cat < A > D

(Redirects standard input using A as input for command and output will be directed to D)

cat < A

(Redirects standard input using A as input for command and output will be in terminal)

c. In the list of names, which kinds of names would you expect to be statically bound? Dynamically bound? Why?

**Users can change URLS or local symbolic names need a mapping mechanism for each, except addresses which are for hardware

f. What happens if the OS decides to page out the shared page then reload it later in a different frame?

*The respective maps in every process would have to be updated to ensure that all the processes can appropriately reach the new memory location.

return EXIT_SUCCESS;

; #parent resumes execution

Why put capabilities in directories instead of giving them directly to users?

A directory is a table that matches external names of objects to internal names. The directory allows the user to deal solely with recognizable, meaningful strings as object names without having to import system names into an address space (where they can be misused or damaged). (pg 10 os99)

What is a pipe?

A pipe directs the output of one program to the input of another program. A pipe could be a file that stores the data from one VM and is read by the next VM.

g. How do processes using the shared page avoid race conditions?

A semaphore is often utilized to prevent races. The use of the wait(s) and signal(s) function protects the points in the code where the shared resource is referenced. A semaphore around the critical section. Treat variables on the shared page as critical sections.

a. The shell parser makes state transitions in response to tokens making up the command line. What is a token?

A token is an object that is separated by | > < or is the first or last item in the command line. Another way to say it would be white space, operators, or EOL .

Once the shared page has been added to the process's address space, how does the process know what page number it is?

A user process declares that a group of processes share a page, and set aside that VM address when the programs are called. The process then keeps this VM address within its address space. Page_id = get_page (shared_id)

. What is a pathname?

An absolute path that are interpreted relative to the root directory. A series of symbolic names from root to object in a directory tree.

e. Notice how we can associate with each transition of the state diagram an action that says what the operating system is to do to build the next increment of a virtual machine pipeline for the command. How do we know when it is time to ask the OS to create a virtual machine?

Associate action code with each state. Action code examines allowable symbols, specifies next state, and gives next entry in output script. Script tells what OS calls are needed to implement the command. Action code for state 0 initializes counts (v,p) of virtual machines and pipes created. (from shell.pdf)

a. Discuss how OPEN, CLOSE, READ, and WRITE operations, which you have already seen for files, can be re-specified for this generic interface.

Because x is generic in this case and the Info Object (pipe, file, and device) are interchangeable it could be made generic using the tag in the capability pointing to the object.

b. How do the generic operations know which subsystem to invoke? For example, if you want to read a file pointed by capability c, how does the READ(c) generic operation know that it should redirect that to the READ_FILE operation?

By reading the type field or tag of the handle(capability), it will translate to open, close, read or write for that specific operation of a file, pipe, or device.

a. What defaults does the OS provide as the standard input and output to the date virtual machine?

Keyboard is standard in and display is standard out.

pid_t pid = fork();

Calls fork system call to split execution to two processes; pid_t is the return value of fork

definition of cat

Cat command concatenates and prints files; reads files sequentially, writing them to the standard output.

Look up the definition of cat command and, in each of the above cases, explain what is supposed to happen and draw diagrams showing the virtual machines structure the OS sets up. cat A B C cat A cat < A cat < A > D

Cat command concatenates and prints files; reads files sequentially, writing them to the standard output. The file operands are processed in command-line order.

cat

Concatanates two processes

e. How can we wind up with a tree of directories? Why would we want to permit trees of directories?

Directories can be hierarchical and have a one directory contain a file name file number mapping to another directory. Trees of directories assist in finding an entry faster. If there was only one directory for all then it would take time to find the entry.

The book says that a directory is a special form of file. The reference model [os99.pdf] says that a directory is an object but not a file. In what way are both right?

Directories do not use the standard method of open/close/read/write which means it is different than a file. However, the directory keeps a list of name file name mappings. They are both write because the directory is different from a file in that it is accessed differently and even with the slight difference it is still an object. Directory is not a file but could be stored in a file

a. In everyday jargon, we often use the terms "file directory" or "files folder" for a directory; why are these terms inaccurate?

Directories point to digital objects not just files and maps symbolic name to a capability. The everyday jargon would make one believe the file is in the directory or the files are in the folder when they are far from being stored in the directory.

*****e. The network protocol stack also uses levels. Data packets on the sending machine are passed downward through the levels, acquiring additional header bits from each level. On the receiving machine the packets move upward, being stripped of a level's special bits when they pass through. This is a level-structured dataflow rather than a call-return structured procedure flow as in an OS kernel. Why not use the same dataflow principle for the OS levels?

Efficiency. The advantage for OS levels is a program that does not use a given function will experience no overhead from that functions presence. (4.1 pg 11 os99)

d. What could go wrong if we allow a directory to have multiple entries with the same symbolic name, for example (S,c1) and (S,c2)?

If multiple entries with the same symbolic name, you could overwrite the file you wanted with a different file. The capability that would be used could be inaccurate. It could use c1 or c2 which could be different access or different pointers to different locations.

a. The implementation of a file is not a contiguous block of bytes on the disk. It is some sort of tree structure with an index record at the start, pointing to other index record to directly to individual blocks of the file. Why not just allocate a single contiguous region of the disk for the file?

Files are different sizes and this could lead to wasted space. If the file grows it will be fragmented and store the fragment of the file in a different location instead of moving the entire file.

h. Suppose a process sets out to copy array A[1..N] to the shared page, beginning at offset 0 of the shared page. What happens if N is larger than the page size? Does this cause a problem?

If N is larger than the page size, it will overflow into the next virtual page. This causes problems due to overwriting the adjoining processes data.

5. Consider the command line Lastcommand < outfile | cat | sort > infile a. Under what conditions is this a valid command line?

If lastcommand is a command of a program then it would be valid. The parser knows that the first position is a command name and the second is a file name.

c. The graph of the shell accepter does not account for every possible string a user could type. What happens if parser is in a state such that the next input token does not match any state transition from that state?

If the parser is in a state that the next input token does not match it will create an ERROR.

Why isn't the OS paying attention to the meanings of the program and file names in this command? Lastcommand < outfile | cat | sort > infile

If the syntax is correct and the commands and files exist it will execute.

a. What could go wrong if users could modify capabilities?

If users could modify capabilities they could move the pointer to a malicious object or they could modify the access the object has, like allowing a user to read or write to something they shouldn't have access to.

<

Input redirect: commands that normally take their input from the standard input can have their input redirected from a file in this manner.

a. Why are private semaphores useful here?

It ensures that only one process is executed at a time. Once the Process(es) has been put into the queue, it is not woken up until after the Disk is complete and the interrupt is triggered.

e. How does the operating system know when it is time to delete the shared page?

It is deleted per whatever replacement policy is used to clear the VM cache (Working Set, MIN, etc) but may want to exempt shared processes.

a. Why would we be interested in handles that are unique-for-all-time?

It is important for the handles to be unique for all time so that they are able to have access control measures put in place. If a file handle was reused and capabilities were assigned to the first file, if another file came along with the same name it could possibly violate access control by having access that is not meant for that file. Unique handles prevent this from happening. ?So you don't overwrite other peoples values.

b. The pseudo code shows only one process P. The real system has multiple processes like P all generating disk requests. Should the add operation in P and the remove operation in D be treated as critical sections protected with a mutual exclusion semaphore? If not, why? If so, define the semaphore, its initial value, and the placement of its wait and signal operations.

It should be treated as CS's because all processes are queued and put to sleep until the disk decides it is ready for the next process. There should be a semaphore within the disk driver input queue to prevent race conditions while trying to access the queue. The semaphores initial value is zero and its placement would be wait before the add/remove and a signal when it is done adding to the queue. Addsema =semaphore (1) Remsema = semaphore(1) Wait(addsem) Add() Signal(addsema) To remove: Wait(remsema) Remove() Signal(remsema)

d. What happens if a command line element names a file or command executable that does not exist?

It will create an error.

d. How does the operating system learn which processes are in the group sharing a particular page?

It will learn it via a kernel call that declares a group process that will share a page. E.g Group-id = make-group(list of process ids)

a. What is meant by location independence?

Location independence is the ability to move things around without changing their names. (From E6 pdf) Location independence also means that you do not reveal the physical location of the file.

d. Is it possible for this code to lose or duplicate a request?

No One request at a time then deletes from queue.

c. Do all the processes in the group need to use the same page number for the shared page?

No. Internally, they may use VM addresses that are distinct and different. However, when translated, they will map to the same frame.

c. Could the pipe symbol (|) be the last symbol of a valid command line?

No. it is looking for the successor command. The pipe is a connector between two objects

Unix exec:

Once set the child calls exec which brings the new executable image into memory and starts it running; takes two arguments (name of program to run and array of arguments to pass to program)

b. How does the date process read the system clock?

Shell sets up the virtual machine with the thread date.

a. Why do OSes have to deal with so many kinds of names? (

Operating systems deal with multiple kinds of names so it will know what kind of object it is and how to handle it. It uses the names it receives to translate to the object's location in memory. (From E6 pdf) *They exist and meant to be managed and mapped in the OS.

>

Output redirect: If the notation > file is appended to any command that normally writes its output to standard output, the output of that command will be written to file instead of your terminal.

|

Pipe, connects the output of one process to the input of another

c. Many operating systems provide a kernel call SLEEP, which causes the caller to wait on its private semaphore, and a corresponding command WAKEUP(j) to signal the private semaphore of j. Show pseudocode for implementing SLEEP and WAKEUP

SLEEP = Wait(privateSemaphore[self]} WAKEUP(k) = Signal(privateSemaphore[k])

i. UNIX introduced the idea that every directory contains two default entries: a single dot meaning "current directory" and double dot meaning "parent directory". What are these entries used for?

Single dot is used to references the users current directory. for example ./a.out means run this in the current directory Double dot is used to refer to the parent directory to the current directory you are in. for example cd .. means change the directory to the parent directory

d. In part (c), the object manager returns a capability that goes into a directory. The directory manager is higher in the level structure than the object manager. How can we get the capability into the directory without violating the principle that a lower level knows nothing about a higher level?

Structure allows downward call and upward return. Process running at shell level can call down.

b. The Windows command line window implements the pipe not as a new kind of object but as a temporary file. The meaning of command A|B is: the output of A is put in the temp-file. When A has terminated, B starts and reads the file as its input. How does this differ from the UNIX pipe?

The Unix VM run in parallel (Concurrently) and ensures they don't get ahead of each other. Windows gets sync by making the VMs go in strict order.

What does the command WAIT(self) do?

The command WAIT(self) is used in private semaphore to put the process asleep.

c. Is it possible for this code to deadlock? If not, prove it. If so, give an example of a deadlock.

The only way for this program to deadlock is if the DCI (Disk Completion interrupt) handler was not triggered when the disk sends a disk completion signal. NO- there is a last in first out chain of waits lending to DCI. Cannot get a circular wait from this.

a. A pipe is used to transmit a stream from process A to process B. What happens when A writes and B reads? How do we know that B never gets ahead of A in the pipe?

The output of A goes to the input of B. Because B is waiting for as output.

b. What output will be generated by this command line? Where will it go? cat < A | sort

The output will go to the standard output default, the display. The output will be the sorted output from the output of cat<A.

b. Devise a method for generating unique-for-all-time file handles. The method should work even when two processes on different machines of a network create a new file at exactly the same time.

The process of creating a unique-for-all-time handle is by taking the timestamp and the MAC address.

b. When designing the state diagram, how do we know what states to use and which transitions are allowable?

The state diagram starts with the GET to get input for the tokens, starting with state 0 to initialize the virtual machine and pipes. For each state, it checks for a specific condition (such as white space, operators, or EOL) and moves to the next state or goes to the standard out. To know what is allowable you would know what the parser would semantically allow.

c. How does the object manager verify that incoming capabilities point to the objects it manages? For example, how does the file system verify that incoming parameter capabilities actually designate files?

The tag in the capability will tell it what kind of object it is, such as a file, device or pipe.

d. In a distributed system, we use cryptographic checksums to guarantee unforgeability. Describe how this would work.

This takes the tag, access, and pointer fields and runs them through a crypto function and then makes it smaller (for example a 64 bit crypto checksum down to 16 bits) and store it in the capability list. This allows for verification that it has not been tampered with. Would need PK (Public Key) system to get signatures

a. Specify a command interface that a process can use to perform these operations. Draw a diagram to show a set of processes in a group sharing a page frame.

Two different processes can simply have a pointer to the same space in the virtual memory. The OS oversees the deconfliction/grouping of which programs are sharing which space.

b. What benefits are provided to users by location independence?

When used in a large network it allows users to access files and services that can be moved anywhere without prior notice and without having to update anything. (From E6 pdf)

b. Can users who want to see their capabilities in raw bit-encoded form do so?

Yes. However the OS provides protected space for processes to store capabilities.

b. Could we list any object, not just files, in a directory?

Yes. Unix points to any digital object. (some OS's do not do this).

g. Is a pathname a unique name for an object in a system?

Yes

d. Are UNIX/LINUX file handles location independent?

Yes, Unix and Linux file handles are location independent.

e. Are Internet domain names (e.g., nps.edu) location independent?

Yes, because they can be used machine to machine and the name does not change, machine can be anywhere

f. Are Internet IP addresses (e.g., 205.155.65.20) location independent?

Yes, because they can be used machine to machine and the name does not change, mostly but there is some correlation with locations.

b. Could a protected C-list implement this ideal?

Yes, by using the cryptographic checksum. C-list is in OS space protected from users. Checksum not needed until shared on network.

c. Are pages of a virtual memory location independent?

Yes, pages of a virtual memory are location independent, they are virtual and can move at any frame.

. Does the variety of names increase vulnerability to attacks?

Yes, the variety of names increases vulnerabilities. *The more names, the more things to protect

Unix fork:

creates a complete copy of parent process; child sets up privileges, priorities, and I/O for the program; takes no arguments and returns an integer

How the date command reads the system clock and displays the current time on the users display in a VM (Process) diagram.

keyboard is stdin Display is stdout


Related study sets

Nursing Fundamentals 226 Chapter 24 Asepsis and Infection control Prep u quizzes

View Set

The Home Observation for Measurement of the Environment- HOME

View Set

Nursing Care During Labor Chapter 10

View Set

Module one: developmental stages and transitions exam

View Set