Midterm 2 - CS3113

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Based on Dr. Grant's code during his lecture on 9/27, --- Suppose you are given the following code: char a[] = "it's spooky season!"; char *b = "it's spooky season!"; a[5] = 'a'; b[5] = 'b'; printf("This character is %c\n", a[5]); printf("This character is %c\n", b[5]); What will be printed?

(A) Nothing. Since char *b is a pointer to a literal string, not an array like char a[], you cannot change individual elements by assignment. char a[] allows changes due to it copyng the contents of the string into an array.

According to Dr. Grant's "processes-i.pdf" presentation from week six, what form of memory is the highest form of memory in a C program? --- A. argc, argv B. initialized data C. uninitialized data D. text E. heap

(A) The correct answer is A. Argc and argv is classified as high memory in a C-program.

According to file-io.pdf from Week 5, which of the following values is returned when there is a error trying to close a file. Example code for closing a file: int close(int fd); --- (A) -1 (B) 0 (C) 1 (D) 2 (E) Null

(A) This is the correct answer. Because anytime there is an error while closing a file a -1 is returned.

According to the file-io.pdf listed in the week 5 module, which open command would open a file with the read-only flag whose name was passed in through the command line? --- (A) open(argv[1], O_RDONLY); (B)open(argv[0], O_RDONLY); (C) open(argv[1], O_RDWR); (D)open(argv[0], O_RDWR); (E)open(argv[1]);

(A) This option is correct. argv[1] specifies the name passed in through the command line and O_RDONLY is the correct flag

According to Dr. Grant on September 27th, which of the follow can you not call lseek on? (i.e. it will return an error) --- A) Terminal input. B) .zip C) .json D) .txt E) .rtf

(A) is correct. lseek requires a file's data to be able to operate on.

According to Dr. Grant's CS-3113 Lecture 10: File IO and the system_calls.pdf from Week 5, what happens when you use the command strace? --- A. strace lets you see the system calls being called by a program from any other program. B. Shows your history C. it returns a binary representation of the object passed in D. It starts watching for a stack overflow error E. It's used to access a track back error

A

According to Dr. Grant's lecture on processes from week 6, In the memory layout of a C program, what is the order of memory from lowest to highest? --- A. 1. text 2. initialized data 3. uninitialized data 4. heap 5. stack 6. argc/argv B. 1. uninitialized data 2. initialized data 3. heap 4. stack 5. argc/argv 6. text C. 1. heap 2. stack 3. initialized data 4. uninitialized data 5. argc/argv 6. text D. 1. argc/argv 2. heap 3. text 4. initialized data 5. stack 6. uninitialized data E. 1. argc/argv 2. stack 3. heap 4. uninitialized data 5. initialized data 6. text

A

According to lecture 12 what is the fundamental difference between using malloc and calloc in the c language in terms of memory allocation. --- A) Malloc allocates memory on the stack and calloc on the heap therefore calloc uses less space B)malloc() indicates memory allocation. calloc() indicates contiguous allocation. C) malloc has fewer arguments and therefore requires less space D) malloc uses less space than calloc E) Calloc is for losers and malloc is for winners

A

During Dr. Grant's lecture on September 27th [Processes-i], which of the following variables is a string literal? --- A: char *name = "name"; B: char name[4] = {"n","a","m","e"}; C: string name = "name"; D: char name[4] = "name";

A - This is correct because a string literal is a reference to a sequence of characters stored in memory. Using char * creates a string literal that cannot be changed once initialized.

According to system_calls.pdf from week 5, what does the syscall errExit(<str>) do? --- A. prints <str> and a description of the error encoded by errnoto STDERR B. prints <str> and a description of the error to STDOUT C. Returns file descriptor, or -1 on error D. Returns number of btyes read, 0 on EOF, or -1 on error E. Returns 0 on success or -1 on error

A This answer is correct. errExit(<str>) prints <str> and a description of the error encoded by errnoto STDERR and then exits your program.

According to Dr. Grant's CS 3113 lecture 10 on File IO, when using malloc or calloc, how can memory leak be prevented? --- A. free(myarray) B. close(myarray) C. open(myarray) D. open(fd) E. There won't be memory leak issues

A by freeing it

According to Dr. Grant's lecture on processes-i on September 27th, what mode are Unix SVR4's system processes run? --- A. kernel mode B. user mode C. execution mode D. state mode E. program mode

A is correct because UNIX SCR4 uses the model where most of the OS executes within the environment of a user process and kernel mode handles system processes in kernel mode by executing OS code to perform administrative and housekeeping functions.

According to Dr. Grant's lecture on September 20, 2022 (Syscalls), when using the command 'hexdump' on a file, how are the values ordered and printed? Suppose the file only has "abc" in it. --- A. 0000000 6261 0a63 0000004 B. 0000000 6162 630a 0000004 C. 0000000 abc\n 0000004 D. 0000000 101010111100 0000004 E. 616263

A is correct because hexdump orders the characters backwards and in pairs, and translates each character to ASCII. For example, if a file had "ABCD" in it, the order in which it is printed would be "BA DC", but in ASCII and with a newline at the end (LF, or 0a in ASCII).

According to Dr. Grant's lecture and syscalls.pdf on Thursday, September 22, 2022, which is not a way to assign macros to help with defining the compiling context? --- A. fd = open("macros", O_MCRO); B. #define MY_CONTEXT C. #define MY_VERSION 7 D. gcc -DMY_CONTEXT hello.c -o hello E. gcc -DMY_VERSION=7 hello.c -o hello

A is correct because it is not a way to assign macros and because there is no such flag argument for the open().

According to Dr. Grant's Lecture (Syscalls) on September 20, when a system call is initiated, the wrapper function calls which function when transitioning to Kernel mode? --- A. Trap handler B. Application program C. System call service routine D. Timeout E. Main

A is correct because the Trap handler is the safety feature to limit access when going from the User mode to Kernel mode.

According to section 3.3 Operations on Processes of our book Operating System Concepts, what is the return value from fork() when the child process is successfully created? --- A. 0 B. -1 C. positive value D. negative value E. spork

A is correct, zero is the return value from fork() when the child has been successfully created.

According to file-io.pdf from the Week 5 module, as well as Dr. Grant's Lecture #9 (Syscalls) from September 20th, 2022 what are the parameters for the open system Call? --- (A) open(pathname, flags, mode)(B) open(fd)(C) open(mode, flags, pathname)(D) open(fd, buffer, count)(E) open(pathname, fd, buffer)

A is correct. The open system call passes a pathname, flags and mode. It opens the file identified by pathname and returns a file descriptor.

According to Dr. Grant's CS-3113 Powerpoint File-IO Lecture 10, which of the following operations correctly represent permissions that are listed: The user has permission to read, write, and execute; the group has permission to read and execute; Others have permission to read? --- A. S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH B. drwxrw-rwx C. Chmod 777 D. S_IRUSR | S_IWUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IWOTH E. Chmod 745

A is the correct answer as it contains the correct calls for user read, write, and execute; group read and execute; and other read.

According to Table 3.2 in processes-i.pdf from Week 6, which of these is NOT a reason for process termination? --- A. New batch job B. I/O failure C. Parent request D. Invalid Instruction.

A is the correct answer because it is a reason for process creation.

According to Dr. Grant's lecture on September 27th for system processes, there are 5 different states a process can be in when executed. Of those 5 different states, which 3 states work dependent of each other when processes are being executed? --- A. Running, waiting, and ready states. B. New, execution, and terminating states. C. Identification, creation, and execution states. D. Binary, waiting, and execution states.

A is the correct answer because these states rely on each other to perform tasks, when a running states runs into an I/O event it turns into a waiting state until completion, once I/O is complete it turns into a ready state, and once the scheduler dispatches the process it turns into a running state again. This situation can happen for many different things just not I/O.

According to system_calls.pdf from the Week 5 module, which of the following system calls creates a new file independent of passed in flags and returns the file descriptor, or -1 on error? --- A) int creat(const char *pathname, mode_t mode); B) ssize_t read(int fd, void *buffer, size_t count); C) ssize_t write(int fd, void *buffer, size_t count); D) int close(int fd); E) int open(pathname, flags, mode);

A) This is right answer, creat() creates a new file and returns its file descriptor.

According to the project 0 instructions, when looking at a binary representation of a character, which of the following is true? --- A. 4 bits is a nibble and two nibbles is a byte B. a byte and a nibble have the same number of bits C. each number is a nibble and two nibbles is a byte D. two bits is a nibble and two nibbles is a byte E. you take two nibbles and a bite of a cookie to eat it

A) four bits make up one hexadecimal number and two of those is a byte

According to Dr. Grant's lecture 10 (file io) and Project 0 instructions, which would be the correct way to check if the first byte of a unicode character stored in the variable 'buf' will be made up of 4 bytes? Consider the following code: unsigned char buf; int readval; readval = read(0, &buf, 1); --- Answer Choices: A) if((buf & 0xF0) == 0xF0) B) if((buf & 0xE0) == 0xE0) C) if((buf & 0xC0) == 0xC0) D) if((buf & 0x80) == 0x80)

A) if((buf & 0xF0) == 0xF0) is the correct answer. If the first byte of a unicode character is in the form 11110xxx, this means that the character will require 4 bytes. Using the bitwise AND with a value of 0xF0(11110000 in binary) will show if the character meets that criteria.

According to process-i.pdf from week 6, after a process has been created, the Kernel can do one of the following as part of the dispatcher routine, which one can/should it not do? --- A: ignore all and not send the signals B: stay in the parent process C: transfer control to the child process D: transfer control to another process

A) is correct because the Kernel should send some sort of signal for the process to know how to proceed and execute

Why are machines that uses utf-8 able to read a file made by a machine that only works in ascii --- (A) the 128 encoded ascii characters are encoded the same way in utf-8 (B) ascii is a more limited version of utf-8 to save space (C) utf-8 is unable to read ascii and needs special cases to read (D) utf-8 and ascii are not equivalent, utf-8 is how you encode ascii (E) utf-8 and ascii are the same thing

A) utf-8 determines the extra number of bytes by the number of bits that are on starting from the left, ascii only has 7-bits so the first bit will always be 0

According to file-io-pdf from Week 5, which of the answers below is not a key I/O system call? --- A. lseek B. Open C. Read D. Write E. Close

A- although lseek is an I/O call, it is not a key system call

According to file-io.pdf from Week 5, which of the commands below runs a program called progTest and takes an input from the file input.txt and outputs to the file output.txt with errors being put into the file errorCapture.txt. --- A. ./progTest >output.txt 2>errorCapture.txt <input.txtB. progTest > input.txt <output.txt 2<errorCapture.txtC. ./progTest >errorCapture.txt >output.txt <input.txt D. ./progTest >errorCapture.txt 2>output.txt <input.txt E. ./progTest <output.txt 2<errorCapture.txt >input.txt

A. A is correct because the > used for designating stdout is placed before output.txt 2> used for designating stderr is placed before errorCapture.txt < is used to input the file input.txt into the stdin of the given program run with the context ./progTest.

According to Dr. Grant's lecture on September 29, what is the best way to copy the contents from one string to the location of another? --- A. strcpy B. memcpy C. writing a for loop D. writing a while loop E. simply assigning the string to another one

A. A is the correct answer because it is a simple built in function that takes the contents of a string and puts it in the location of another

According to Dr. Grant's lecture on September 27th 2022 (Processes), where are global variables initialized global variables stored in the attached diagram? --- A. Initialized data B. Uninitialized data C. argc/argv D. Stack E. Heap

A. A is the correct answer. This is where initialized global variables are stored.

When using malloc, calloc, or realloc, what is a common compiler warning that may occur when implemented correctly? --- A. "Void* doesn't equal type of [Type]*", where [Type] is the type of the new object. B. "Cannot allocate memory to object because it is an array" C. "Insufficient memory on the stack" D. "Cannot use an uninitialized object as a reference"

A. Is correct, without the ([Type]*) cast, most compilers will complain about the allocation functions giving a non-void* type variable their output. This is the only answer that is a warning, the others are errors or don't exist.

Some processes simply perform a task and exit or have no need to interact with other processes on the system. These are called independent processes. When a process needs to communicate information or affect another process on the system, it is called a cooperating process. According to Silberschatz (Operating System Concepts), the principal reasons for cooperating processes are: --- A. Information sharing, computation speedup, and modularity B. Modularity and transparency C. Computation speedup, obfuscation, and memory reduction D. Redundancy, data retention, and networking E. Lower latency and improved context switching

A. Is the correct answer, several processes may be interested in the same data (information sharing), when applicable partitioning work into several separate tasks can speed up computation, and modularity allows for code reuse and complex systems to be constructed from simple components.

According to Dr. Grant's Lecture 11 (processes i) not all types of files can moved through with the lseek() function. Which of the following *cannot* be navigated with lseek()? --- A. pipe B. zip C. json D. dat E. txt

A. Pipe files are a (usually) temporary path for communication between processes and not a traditional file. Attempting to use lseek() on a pipe file would cause the "ESPIPE:illegal seek" error.

According to Dr. Grant's CS-3113 Lecture 11 on September 27th, 2022, Processes i, which of the following process states does the Running State go to if there is an interrupt? --- A. Ready State B. Waiting State C. Terminated State D. New State E. Remains in the Running State

A. Ready State is the correct answer. Ready State is where the process is waiting to be run and where the process will end up if there is an interruption during the Running State.

According to the processes-i.pdf from Week 6. For the UNIX Process States, which part of the role here is awaiting an event and being swapped to secondary storage? --- A. Sleeping, Swapped B. Asleep in Memory C. Preempted D. Ready to Run, Swapped E. Created

A. Sleeping, Swapped is correct, the process is awaiting an event and has been swapped to secondary storage (a blocked state)

According to the processes-i pdf listed in the week 6 module, What is the Unix process state that signifies that the process no longer exists, but leaves a record for its parent process? --- A. Zombie B. Preempted C. Created D. Asleep in memory E. User running

A. The Zombie process state is correct

While a process is waiting to be executed on a CPU core they are put into the ___ where the ___ allocates cores to one of the processes in the queue. --- (A) Ready Queue; CPU Scheduler. (B) Wait Queue; Context Switch (C) Wait Queue; Parent Process (D) Ready Queue; Context Switch (E) Stack; Context

A. The ready queue hold the list of processes ready to be run by the CPU then the CPU scheduler decides which processes to allocate cores to.

According to Dr. Grant's week 5, lecture 10 (File io), given the binary octet file permissions: [000] [000] [111] who can read, write, and execute? --- A. the world B. the user C. the group D. user, group, and world E. Dr. Grant only

A. The world is the correct answer as the order for file permissions goes: [user] [group] [world] and all toggles for the world are on.

According to the processes-i.pdf from Week 6, what should be inserted into the given field in the following code to successfully let both parent and child run their corresponding code and keep track of the child? pid_t childPid; switch({CODE TO INSERT}) { case -1: /* Handle errors */ case 0: /*Perform child actions*/ default: /* Perform parent actions */ } --- A. childPid = fork() B. parentPid = fork() C. fork() D.childPid

A. This code is correct as it assigns the return of fork, which is always the process ID of the child (0) on success, or it returns -1 on error.

According to system_calls.pdf from week 5, which syscall is used to print an error message and a description of the error encoded by errno to STDERR? --- A. errExit(<str>) B. perror(<str>) C. printf(<str>) D. read(fd, buffer, count); E. write(fd, buffer, count);

A. This is answer is correct. This syscall prints the given string and the description from errno, which is a global variable set by the kernel side of the syscall to provide more details.

According to processes-i.pdf from Week 6, what does the wait() function return on error? --- A.) -1 on error B.) NULL C.) 0 D.) ID of terminated child E.) 2

A. This is correct because based on the slides wait() returns -1 on error.

According to the file-io.pdf from the Week 5 module, what is NOT true of the file offset? --- A. The file offset is not adjusted by calls to read() or write(). B. The file offset points to a byte in the file. C. The first byte of a file is at offset 0. D. The file offset can be repositioned. E. The file offset can be positioned past the EOF.

A. This is false. For operations like read(), the file offset is adjusted by the number of bytes read.

According to Dr. Grant's CS-3113 Lecture 10: File IO and the system_calls.pdf from Week 5, what does the command strace do? --- A. strace lets you actually see the system calls that are run by each of our programs, by any program that we have. B. strace traces your last few commands used. C. It gives a dump of data in hexadecimal format. D. It returns a value indicating success/status or an error of a system call wrapper. E. It is GDB which is a GNU debugger.

A. This is the correct answer because strace can be seen as a light weight debugger. It allows a programmer / user to quickly find out how a program is interacting with the OS. It does this by monitoring system calls and signals.

According to processes-i.pdf from Week 6, what does the process state Ready mean? --- A. The process is waiting to be assigned to a processor B. The process is being created C. Instructions are being executed D. The process is waiting for some event to occur E. The process has finished execution

A. This is the correct answer, it describes the process state Ready

According to syscalls.pdf from Week 5, which answer choice is true regarding the following terminal input ./myprog <input.txt >output.txt 2>error.txt --- A. stdin is mapped to input.txt B. stdout is mapped to input.txt C. stderr is mapped to output.txt D. input.txt is the new process/program to be run E. myprog is deleted

A. This is the correct answer. "./myprog <input.txt" would map stdin to input.txt

According to Dr. Grant's lecture on September 20th, 2022 (Lecture 9 File-io), which of the following is not a flag for the open() function? --- A. O_PEDANTIC B. O_RDONLY C. O_RDWR D. O_WRONLY E. O_CREAT

A. This is the correct answer. -pedantic is a flag used when compiling to help see warnings and errors in your code.

According to Dr. Grant's lecture on September 27, 2022 (processes i), after a process finishes the state of "waiting" for I/O or event wait, which process state will it change to? --- A. Ready B. Running C. New D. Terminated

A. This is the correct answer. After I/O or event completion, the process will change to the ready state.

According to syscall lecture from Week 5, which answer is not correct about syscall process? --- A. Each sys call is referenced by same number B. There is one common entry point for all system calls: this is done through the sys call "trap" instruction C. Each has its own set of argument to be transferred D. The trap instruction switches the processor state from user to kernel mode E. The trap handler function then translates the sys call number into an appropriate function call

A. This is the correct answer. It must be like "Each sys call is referenced using a unique number"

According to file-io.pdf from Week 5, how to open file to read only? File* fd=open(pathname, ******); --- A. O_RDONLY B. O_WRONLY C. O_RDWR D. O_CREAT E. readOnly

A. This is the correct answer. O_RDONLY this one opens file for read only.

According to Dr. Grant's lecture on September 27, 2022 (processes-ia.pdf), which of the following statements about the process control block (PCB) are NOT true? --- A. Can control the entire operating system's information B. Contains the process elements C. Possible to interrupt a running process and later resume execution D. Created and managed by the operating system E. Key tool that allows support for multiple processes

A. This is the correct answer. The PCB can only control a certain process's information, not the entire operating system.

According to Dr. Grant's lecture on on September 20th, 2022 (Lecture 9 Syscalls), what line of code do we need to add above the printf( "The input data was: %s\n", buffer); line in order for the string to be complete? #define MAX_read 20 char buffer[MAX_READ + 1]; ssize_t numRead; numRead = read(STDIN_FILENQ, buffer, MAX_READ); if (numRead == -1) errExit("read"); What line goes here? printf("The input data was: %s\n", buffer); --- A. buffer[numRead] = '\0'; B. buffer[numRead] = '\n'; C. buffer[numRead] = "\n"; D. buffer[numRead] = numRead; E. buffer[numRead] = MAX_READ;

A. This is the correct answer. The null terminator must be added in order for a string to be complete.

According to file-io.pdf from Week 5, which answer choice describes what happens with this system call? fd = open(pathname, flags, mode) --- A. opens the file identified by pathname, returning a file descriptor. B. reads at most count bytes from the open file referred to by fd and stores them in buffer. C. writes up to count bytes from buffer to the open file referred to by fd. D. is called after all I/O has been completed, in order to release the file descriptor fd and its associated kernel resources. E. This is an invalid system call.

A. This is the correct answer. The open system call opens the specified file returns a file descriptor.

According to file-io.pdf from the Week 5 module, what happens if a FILE pointer named fp fails to open? --- A. The value of fp is -1 B. The value of fp points to the memory address of the file C. The value of fp returns its operation flags D. The file is created and assigned to the fp pointer

A. This is the correct answer. The value of fp is -1 which means the file was not found.

According to Dr. Grants lecture on September 20th 2022 (Syscalls), Which of the following is NOT a example of a syscall function? --- A. strcpy() B. read() C. close() D. creat() E. write()

A. This is the correct answer. strcpy() is not a syscall function. This is a standard library function that is used to copy one string to another.

According to Dr. Grant's lecture on September 20th, 2022, from week 5 (Lecture 9 Syscalls), when should you use "size_t" --- A. Anytime you are using something that is architecture dependent. B. When the amount is known C. When the amount is limited D. When you are worried about size and speed E. "size_t" is a user defined variable, use when you like

A. This is the correct choice. For example if you have a character array and you are iterating through it then it would be a good time to use size_t.

According to processes-i.pdf from Week 6, which of the following is the first step of the Process Creation? --- A. Allocate a slot in the process table for the new process B. Assign a unique process ID to the child process C. Assign the child state to the Ready to Run state D. Make a copy of the process image of the parent, with the exception of any shared memory E. Increments counters for any files owned by the parent, to reflect that an additional process now also owns those files

A. This is the correct option as a slot needs to first be created to allow the new process to occur.

According to system_calls.pdf from Week 5, what is the proper way to type a Macro? --- A. #define KEY B. //define KEY C. /* define KEY */ D. """define KEY E. <!-- define key -->

A. This is the proper way to declare macros. These macros can also be defined in gcc, such as gcc -KEY hello.c -o hello or to define a value, gcc -KEY=VALUE hello.c -o hello. This acts similar to environment or env values, where the compilation or running scripts can be changed depending on the environment variables of the machine. e.g. having production or development defined can have debug tools be hidden or shown.

According to Dr. Grant's Lecture 11 (processes-i) on September 27, 2022 and processes-i.pdf from Week 6, which of the following is the highest memory in the memory layout of a C program? --- A. command line arguments B. stack C. heap D. uninitialized data E. text

A. command line arguments is the correct answer. It is considered the highest memory in the memory layout of a C program. Ex: argc, argv

According to the processes-i powerpoint, which of these is lowest in the memory layout of a C program? --- A. initialized data B. arc, argv C. heap D. stack E. uninitialized data

A. initialized data is the correct answer. It is not the lowest of all memory in a C program, but it is lowest option given being 1 from the bottom

According to "processes-i.pdf" covered in week 6, which of the following is NOT a task completed by the OS in Kernel mode during process creation? --- A. Transfer control to the child process B. Assign the child process to the Ready to Run state C. Copy process image of the parent, with the exception of shared memory D. Allocate slot in process table for the new process E. Assign unique process ID to the child process

A. is the correct answer. This step is taken by the kernel AFTER all 6 steps of process creation are completed. This answer may be mistaken since this is likely to be the developer's reason for creating a new process, but the child process needs to be fully created first before this can happen.

According to Dr. Grant's Lecture on Sep. 27, 2022, and the file-io.pdf slides, which of the following lseek calls returns the current location of the cursor in a given file? --- lseek(fd, 0, SEEK_CUR) lseek(fd, 1, SEEK_CUR) lseek(fd, -1, SEEK_CUR) lseek(fd, 0, SEEK_SET) lseek(fd, 0, SEEK_END)

A. lseek(fd, 0, SEEK_CUR) is the correct answer. This call uses the correct byte offset (0) and the correct whence flag for accessing the byte at the current location.

According to Dr. Grants lecture 9 (Syscalls) from week 5, if you wanted to print out a description of your error to STDOUT which syscall would you use? --- A. perror() B. open() C. read() D. write() E. close()

A. perror() is the correct answer, it prints out a string (<str>) and description to STDOUT of the error.

According to file-io.pdf from the Week 5 module, as well as Dr. Grant's Lecture #9 (Syscalls) from September 20th, 2022, which of the following answer choices is NOT an example of a standard file descriptor in C? --- A. stdex B. stdin C. stdout D. stderr

A. stdex is the correct answer because it is not one of the three standard file descriptors. Stdex is a third-party add-on for C, but is not natively available.

According to Dr. Grant's Lecture 11 (processes-i) on September 27, 2022 and processes-i from Week 6, which of the following is the lowest memory in the memory layout of a C program? --- A. text B. stack C. heap D. command line arguments E. uninitialized data

A. text is correct. It is the lowest memory in the memory layout of a C program and contains code instructions.

According to file-io.pdf from Week 5, what is the file descriptor used to read from stdin? --- A.) 0 B.) 1 C.) 2 D.) 3

A.) 0 is the correct answer to read from stdin

According to Dr. Grant's week 6 presentation and lecture "Processes", which of the following is true? --- A: Variables that are defined within contexts are stored on the stack and will be there until we free it B: Variables stored on the heap are only alive within the context of the function C: If you create something dynamically within a function, it would still exist once we leave the context of that function D: Global variables are stored in the same place as local variables (stack and heap)

C) TRUE

According to file-io.pdf from Week 5, which answer choice is called after all I/O has been completed, in order to release the file descriptor fd and its associated kernel resources? --- A: status = close(fd) B: fd = open(pathname, flags, mode) C: numread = read(fd, buffer, count) D: numwritten = write(fd, buffer, count) E: There is no answer choice that has that behavior

The answer is A. The System call used for the situation described is that

According to Dr. Grant's lecture 12, what will be the output of the following code? #include <stdio.h> #include <string.h> int main() { unsigned char str[] = {'s', 't', 'r', 'i', 'n', 'g', '\0'}; printf("%s", str); printf("%lu",strlen(str)); printf("%lu",sizeof(str)); return 0; } --- A. string67. B. string66. C. string77. D. string76. E. gnirts67.

This is the correct answer because strlen() counts the number of characters before the null terminator (6), while sizeof() counts the number of bytes in memory that str occupies, which is 7 because it includes the null terminator.

In Dr. Grants lecture 10 & 12 (File io) & (Project 0 tips) from week 5 & 6, The GNU Debugger (GDB) was discussed and used to debug a segmentation fault. What command can be used in GDB to enter the Text User Interface to see your code while you debug it? --- A: TUI enable B: TUI disable C: break D: next or n E: run or r

a) TUI enable in fact start the Text User Interface where you can see your code while you debug it.

From Week 5: Project 0's instructions and summary of how Unicode + code points work. Question: Assume you are working with Unicode. You want to encode in a character with 2 bytes. What would the first bits of the leading byte look like? --- a. 110 b. 10 c. 1110 d. 0 e. 11110

a. This is correct because 110 is how you would encode for a character with 2 bytes. This itself can already be tricky because someone could interpret this to be like binary and believe the "11" to be 3.

According to Dr. Grant's lecture on syscalls, what definition did he give for "the universality of I/O"? --- A. If a program uses only four system calls - open(), read(), write(), and close() - then that program will work on any type of file. B. Files created on a Linux machine can be opened on a Windows machine. C. If an input device can work on one system, it can work on any system. D. All programming languages have the same interface for implementing I/O. E. All programs are capable of handling I/O.

a. This is correct. As long as you have an I/O device and a file descriptor, then these system calls can perform I/O on any file type.

According to processes-ia.pdf from Week 6, which of the following statements are true about traps and interrupts? --- A. Interrupts relate to events external to a running process. Traps relate to errors and exceptions generated inside of a running process. B. Traps make use of a 'Time Slice' which is the maximum amount of time a process can run before the trap is executed. C. Interrupts execute due to memory faults and clock interrupts, while traps are typically executed due to I/O interruptions. D. Interrupts handle errors and exceptions while traps react to events that are asynchronous and external to a process. E. Both interrupts and traps make calls to an operating system function.

a. True. Traps are executed upon encountering errors or exceptions within a running process. Interrupts execute due to external, independent events that are asynchronous to a running process.


Kaugnay na mga set ng pag-aaral

Chapter 9 - Strategy Review, Evaluation, and Control

View Set

AP European History 5x5: 1815-1914

View Set

Chapter 2: Cognitive Neuroscience

View Set

chapter 9 study questions hth 245

View Set

Ch 26: Vascular Disorders and problems of Peripheral Disorders PrepU

View Set