Midterm1 Polling Questions 1-6 Flashcards

Lectures 1-6

1
Q

Which of the following statements concerning open source operating systems is true?

  • Solaris is open source
  • Source code is freely available to read
  • they are always more secure than commercial, closed systems
  • all open source operating systems share the same set of goals
A

Source code is freely available to read

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Which of the following operating systems is not opern source?

  • Windows
  • BSD UNIX
  • Linux
  • PCLinuxOS
A

Windows

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A ____ is a custom build of the linux operating system

  • LiveCD
  • Installation
  • Distribution
  • VMWare Player
A

Distribution

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Operating System

  • Is a collection of programs
  • provies user-interface
  • is a resource manager
  • all of the above
  • none of the above
A

All of the Above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

The Operating System kernel consists of all system and application programs in a computer

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The operating system model consists of..

  • a kernel layer, service layer, and user interface layer
  • hardware layer, and software layer
  • multitasking, time sharing, and multiuser
  • system layer, utility layer, and appliation layer
  • none of the above
A

a kernel layer , service layer, and user interface layer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The Kernel Layer manages all the hardware dependent functions

True of False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What would a computer without an operating system be like?

  • the software applications you wrote couldn’t send requests to the hardware through standard APIs
  • there would only be one program running at a time and exiting
  • there would be no graphical user interface
  • all of these
A

All of These

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

An OS should be able to handle interrputs or signals that are triggered by either hardware or software

True of False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

In a C program a mandatory main() function is the start of the execution

True or False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

“#include<stdio.h>"in a progarm means</stdio.h>

  • Include header files in code before compilation
  • Stdio is a predefined standard library of functions under a system path
  • contains function definitions that may be called in this file
  • all of the above
A

All of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

include “mylib.h” in a C program means

  • incllude header files in code before compilation
  • mylib is a user defined library of functinos under this directory
  • contains function definitions that may be called in this file
  • all of the above
A

all of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

define in a C program may be

  • constant
  • preprocessor directive
  • replaced by preprocessor in code before compilation
  • all of the above
A

all of the above

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

An operating system is far easier to port to move to some other hardware if it is written in a lower level language(like assembly)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Indicate whether the expression evaluates to true or false. Let x = 7, y = 9.
NOT ( (x > 5) AND (y < 20) )

true or false?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Given numPeople = 10, userKey = ‘q’. Indicate whether the expression evaluates to true or false.
(numPeople >= 10) && (userKey == ‘x’)

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Given numPeople = 10. Indicate whether the expression evaluates to true or false.
!( (numPeople == 5) || (numPeople == 6) )

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Which operator is evaluated first in C?
w + 3 > x - y * z

A

*

Unary operators, like ! ++ –, have a higher priority than % * / + -.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

In what order are the operators evaluated?
w + 3 != y - 1 && x

a) +, !=, -, &&
b) +, -, &&, !=
c) +, -, !=, &&

A

c) +, -, !=, &&

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

To what does this expression evaluate, given int x = 4, int y = 7.
x == 3 || x + 1 > y => (x == 3) || ((x + 1) > y )

A) True(1)
B) False(0)

A

False: B (x == 3) || ((x + 1) > y)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

Which illustrates the actual order of evaluation via parentheses?
! green == red

(!green) == red
!(green == red)
(!green =)= red

A

(!green) == red

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which illustrates the actual order of evaluation via parentheses?
bats < birds || birds < insects

((bats < birds) || birds) < insects

bats < (birds || birds) < insects

(bats < birds) || (birds < insects)

A

C-> (bats < birds) || (birds < insects)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Which illustrates the actual order of evaluation via parentheses?
! (bats < birds) || (birds < insects)

! ((bats < birds) || (birds < insects))
(! (bats < birds)) || (birds < insects)
((!bats) < birds) || (birds < insects)

A

(! (bats < birds)) || (birds < insects)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Which illustrates the actual order of evaluation via parentheses?
(num1 == 9) || (num2 == 0) && (num3 == 0)

(num1 == 9) || ((num2 == 0) && (num3 == 0))
((num1 == 9) || (num2 == 0)) && (num3 == 0)
(num1 == 9) || (num2 == (0 && num3) == 0)
(((num1 == (9 || num2) == 0) && num3) == 0)

A

(num1 == 9) || ((num2 == 0) && (num3 == 0))

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

If age == 28, then what does this evaluate to?
(16 < age < 25)

A

True(16<28)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How to fix this expression to work as the programmer intended?
(16 < age < 25)

A) (16 < age) && (age < 25)
B) (16 < age) || (age < 25)
C) (16 < age) & (age < 25)
D) (25 > age > 16)

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Given the following code, how many times will the inner loop body execute?
int row;
int col;
for(row = 0; row < 2; row = row + 1) {
for(col = 0; col < 3; col = col + 1) {
// Inner loop body
}
}

A) 6 C) 18
B) 3 D) 5

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is the value of j after the fourth loop?
int j = 0;
for (int i = 0; i < 5; ++i) {
j = j * i;
}

A) 4 C) 64
B) 0 D) 128

A

B

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

After the loop terminates can j be printed out (with printf)?
for (int i = 0; i < 5; ++i) {
int j = 0;
j = j * i;
}

Yes
No

A

NO

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What will this code output?
#include<stdio.h>
int main()
{
int n;
for(n = 7; n!=0; n--)
printf("n = %d", n--);
getchar();
return 0;
}</stdio.h>

Infinite loop since n==0 is not satisfied during the for loop
n = 0
n = 1
n = 2

A

Infinite loop since n==0….

only the printf is
executed in for loop

No brackets! {…} means

n is…
7 compared to 0
6 and 5
5 compared to 0
4 and 3
3 compared to 0
2 and 1
1 compared to 0
0 and -1
-1 compared to 0
Fix with n>=0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

These two loops (left and right) produce the same thing
#include<stdio.h>
int main()
{
int i = 0;
int j = i;
while(j < 5) {
printf("%d", i);
j = ++i;
}
...
int i = 0;
int j = i;
while(j < 5) {
printf("%d", i);
j = i++;
}
}</stdio.h>

True or False?

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

These two loops (left and right) produce the same thing
#include<stdio.h>
int main()
{
int i = 0;
while(i < 5) {
printf("%d", i);
\++i;
}
...
int i = 0;
while(i < 5) {
printf("%d", i);
i++;
}
}</stdio.h>

True of False?

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

What is faster n++ or n = n+1?

A

n++

++n is even faster than n++ in theory, since ++n doesn’t return the old value of n but n++ does.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

In C, 1D array of int can be defined as follows and both are correct
int array1D[4] = {1,2,3,4};
int array1D[] = {1,2,3,4};

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What is the index of the last element for the following array:
int pricesArr[100];

A

99

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Given: int maxScores[4] = {20, 20, 100, 50};. What is maxScores[3]?

A

50

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
37
Q

What is the resulting array contents, assuming it starts with an array of size 4 having contents -55, -1, 0, 9?
for (i = 0; i < 4; ++i) {
itemsList[i] = i;
}

-54, 0, 1, 10
0, 1, 2, 3
1, 2, 3, 4
0, 1, 2, 3, 4

A

0,1,2,3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
38
Q

What is the resulting array contents, assuming it starts with an array of size 4 having contents -55, -1, 0, 9?
for (i = 0; i < 3; ++i) {
itemsList[i+1] = itemsList[i];
}

-55, -55, -55, -55
0, -55, -1, 0
Out-of-range access

A

-55, -55, -55, -55

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q

What is the output of this program?
int main()
{
int i;
int arr[5] = {1};
for (i = 0; i < 5; i++)
printf(“%d “, arr[i]);
return 0;
}

a)1 1 1 1 1
b)0 0 0 0 0
c)1 and four garbage (undefined or random) values
d)1 0 0 0 0

A

D

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q

In C, 2D array of int can be defined as follows correctly
int array2D[2][4] = {1,2,3,4,5,6,7,8}; /* (i) /
int array2D[][4] = {1,2,3,4,5,6,7,8}; /
(ii) /
int array2D[2][] = {1,2,3,4,5,6,7,8}; /
(iii) /
int array2D[][] = {1,2,3,4,5,6,7,8}; /
(iv) */

a) (i) is correct
b) (i) and (ii) only are correct
c) (i), (ii), and (iii) only are correct
d) (i), (ii), (iii), and (iv) (all are correct)

A

B

C language doesn’t provide any true support for 2D array or multidimensional arrays. A 2D array is simulated via 1D array of arrays. So a 2D array of int is actually a 1D array of array of int.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

The following is a valid function definition:
void PrintItem() { body consists of C statements; }

True of False?

A

True

42
Q

The following is a valid function definition for a function that returns two items:
int, int GetItems() { … }
True or False?

A

False

43
Q

Given the definition below, is this a valid return statement:
int CalculateSomeValue(int num1, int num2) {
return (num1 + num2) + 1 ; … }
A) True (Yes)
B) False (No)

A

A

44
Q

Given the definition below, is this a valid return statement:
int CalculateSomeValue(int num1, int num2) {
return; … }
A) True (Yes)
B) False (No)

A

B

45
Q

Given the definition below, is this a valid return statement:
int CalculateSomeValue(int num1, int num2) {
return(0); … } //space not strictly needed, better to have
A) True (Yes)
B) False (No)

A

A

46
Q

What will this code output?
#include<stdio.h>
char *getString()
{
char str[] = "Will I be printed?";
return str;
}
int main()
{
printf("%s", getString());
getchar();
}</stdio.h>

A

Doesn’t work - str was a local variable

If you change char str[] to char *str then it will work because the char * points to data stored on the heap or data segment, which is not lost, but a char[] is a local variable that is stored on the stack frame, which is deleted when the function returns

47
Q

What will this code output?
#include<stdio.h>
int main()
{
static int i=5;
if(--i){
main();
printf("%d ",i);
}
}</stdio.h>

5 4 3 2 1
4 3 2 1
1
0 0 0 0

A

0000

48
Q

include<stdio.h></stdio.h>

int fun()
{
static int count = 0;
count++;
return count;
}

int main()
{
printf(“%d “, fun());
printf(“%d “, fun());
return 0;
}

What is the output?
1 2
0 0
0 1
Doesn’t work - count was a local variable
1 1

A

1 2

Static variables have a property of preserving their value even after they are out of their scope! Hence, static variables preserve their previous value in their previous scope and are not initialized again in the new scope.
1) A static int variable remains in memory while the program is running. A normal variable is destroyed when a function call where the variable was declared returns.
Static variables are stored in the data segment (DS) as initialized or uninitialized

49
Q

What will this code output?
#include<stdio.h>
int main()
{
static int var = 5;
printf("%d ",var--);
if(var)
main();
}</stdio.h>

a) 5 4 3 2 1
b) 4 3 2 1
c) 5 5 5 5 5
d) 4 3 2 1

A

A

Print 5, i == 4, if condition is true, main gets called
Print 4, i == 3, if condition is true, main gets called
Print 3, i == 2, if condition is true, main gets called
Print 2, i == 1, if condition is true, main gets called
Print 1, i == 0, if condition is false, main returns (end of recursion)

50
Q

What is Shell?

A

The “Shell” is simply another program on top of the kernel which provides a basic human-OS interface.
It is a command-line interpreter
Built on top of the kernel
Enables users to run services provided by the UNIX OS
A script or Shell program is a series of commands in a file
Saves having to retype commands to perform common tasks

How to know what shell you use
echo $SHELL

51
Q

What will this print out?
int main() {
int i;
i=0;
do {
printf(“%d %c \n”,i,i);
i++;
} while(i<=126);
return 0;
}

A) Integers
B) Characters
C) Ints and Chars
D) Nothing

A

C

52
Q

What will this print out?
int main() {
int e;
char ch;
printf(“\n Enter a character : “);
scanf(“%c”,&ch);
e=ch;
printf(“\n The ASCII value of the character is : %d”,e);
return 0;
}

A) Integers
B) Characters
C) Ints and Chars
D) Nothing

A

A

53
Q

These 3 print statements will print in sequence to:

printf(“%s”, “Hello world\n”); //printf defaults to stdout(1)
fprintf(stdout, “%s”, “Hello world\n”); //stdout is a FILE *
fprintf(stderr, “%s”, “Hello world!\n”); //stderr is a FILE *

a)stdout, stdout, stderr
b)stderr, stdout, stderr
c)stderr, stderr, stderr
d)stdout, stdout, stdout

A

A

Remember to call fflush(); after printf to clear the buffer, if you want it printed immediately!

54
Q

This print statement will print to:

FILE *myFile; //note it is a pointer to a FILE
myFile = fopen(“fileout.txt”, ‘w’);
fprintf( myFile, “my %s has %d chars\n”, “string format”, 30);

a)stdout
b)stderr
c)A file on the filesystem (hard disk)
d)All of these

A

C

55
Q

Will the following two statements both read a single integer from standard input?
fscanf(stdin, “%d”, &x);
scanf(“%d”, &x);
A) True (Yes)
B) False (No)

A

A

56
Q

include <stdio.h></stdio.h>

scanf raises issues: 1) won’t skip leading whitespaces, 2) characters like ‘ABC’ invalid with %d format specifier (for ints) and don’t get discarded, could lead to infinite loops. 3) won’t discard newlines ‘\n’ which will stay in stdin buffer.
Will this fgets read the first char too?

int main(void) {
char line[256];
char ch;
if (fgets(line, sizeof line, stdin) == NULL) {
printf(“Input error.\n”); exit(1); }
ch = line[0];
printf(“Character read: %c\n”, ch);
return 0;
}

A) True (Yes)
B) False (No)

A

A

56
Q
A
57
Q

Modes a Computer can Run in

A
  • user mode
  • kernel mode
  • protected mode
  • real mode
  • virtual mode
  • ## safe mode
58
Q

A(n) ________ is the unit of work in a system.
A) process
B) operating system
C) timer
D) mode bit

A

A

59
Q

In an OS is a “program” the same as a “process”?
A) True (Yes)
B) False (No)

A

B

A program and a process are related terms. The major difference between program and process is that program is a group of instructions to carry out a specified task whereas the process is a program in execution. While a process is an active entity, a program is considered to be a passive one

60
Q

A virtual machine (e.g. in VirtualBox or VMWare) can be switched like any process in the operating system.
Yes
No

A

Yes

61
Q

A new browser process is created by the Chrome browser for every new website that is visited (in the same tab).
True
False

A

False

Chrome is the program which you downloaded from google and resides on disk. When you double-clicked on Chrome (or typed chrome on the cmd line) it became a running process in memory. This is the parent process and it will spawn child processes as it needs. For example it might spawn child processes per tab or per extension. If you have only one tab and you navigate to some websites there is no reason to create new processes just for that.
If you have many tabs open or many plugins installed all the child processes might make your system a bit slow. Generally you should kill the child processes before the parent process (Chrome is a reliable piece of sw so it will kill the child processes when you exit) but if you kill a parent process (and for any reason the child processes are still alive) the child processes will eventually get killed as well by the OS.

62
Q

The ____ of a process contains temporary data such as function parameters, return addresses, and local variables.
A) text section
B) data section
C) program counter
D) stack

A

Stack

Stack is for locally scoped data to functions, and the stack frame of a running function stops to exist after the function returns

63
Q

what does the stack do?

A

Use stack for local variables, function parameters, and return address

64
Q

A process’s stack frame does not contain __________
a) Function parameters
b) Local variables
c) Return addresses
d) Process ID nor PID of its parent process

A

D

65
Q

A stack is a sequentially ordered data structure that uses the first in, first out (FIFO) principle for adding and removing items.
Yes
No

A

No

stack is LIFO

An operating system often uses a stack when invoking function calls. Parameters, local variables, and the return address are pushed onto the stack when a function is called; returning from the function call pops those items off the stack.

66
Q

This program (assume the user presses Ctrl + C at some point to terminate):

int value = 0;
int main(int argc, char *argv[]){
while(1){
printf(“%d”, value);
value++;
}
return 0;
}

Which is an impossible output
(start of output is shown)?
a)012345678….
b)01234567891011…
c)0123456….
d)012301234….

A

D

67
Q

lecture 4 slide 38

A

A

68
Q

In Unix, which system call creates the new process?
a) fork
b) create
c) new
d) wait

A

A

Copies of the stack and the heap are made for the newly created (forked) process

69
Q

When a child process is created inside fork(), which of the following is a possibility in terms of the execution or address space of the child process?
A) The child process runs concurrently with the parent.
B) The child process has a new program loaded into it.
C) The child is meant to be a duplicate of the parent.
D) All of the above

A

D

70
Q

Fork() will copy everything from parent

True of False?

A

False

It will not copy the pid(child has a id -> 0)

71
Q

When fork() creates a new child process:
1. The child gets copies of the parent’s file descriptors
1. The child gets its own separate address space
1. The child gets a copy of its parent process’s memory segments
1. All of the above

A

All of the above

72
Q

Program counter or EIP specifies the current (next) instruction to execute.
A) True
B) False

A

True

73
Q

The address of the next instruction to be executed by the current process is provided by the __________
a) CPU registers
b) Program counter in the EIP register (in Intel x86 arch)
c) Process stack
d) Pipe

A

B

Program counter is process-specific instruction counter

74
Q

include “apue.h”

What does the program print

int
main(void){

printf(“hello world from process ID %ld\n”, (long)getpid());
exit(0);
}

a)The process ID of the current process
b)The parent process ID
c)The child process ID
d)All of the above

A

A

75
Q

What is the ready state of a process?
a) when process is scheduled to run after some execution
b) when process is unable to run until some task has been completed
c) when process is using the CPU
d) none of the mentioned

A

A

76
Q

In operating system, each process has its own __________
a) address space and global variables
b) open files
c) pending alarms, signals and signal handlers
d) all of the mentioned

A

D

D yes these get inherited, but they exist independently in child from parent after the child is spawned/forked&starts running

77
Q

include <stdio.h></stdio.h>

Including the initial parent process, how many processes are created by the program?

#include <unistd.h></unistd.h>

int main()
{
fork();

	 fork();
	 
	 fork();
	 
	 return 0; }
A

8

222

78
Q

include <stdio.h></stdio.h>

Including the initial parent process, how many processes are created by the program?

#include <unistd.h></unistd.h>

int main()
{
int i;
for(i =0; i < 4; i++)
fork();

	 return 0; }
A

222*2 = 16

79
Q

Which system call returns the process identifier of a terminated child?
a) wait
b) exit
c) fork
d) get

A

A

80
Q

lecture 5 slide 26

A

True

81
Q

When will line J be reached?
#include sys/types.h
#include stdio.h
#include unistd.h

int main()
{
/fork a child process/
pid = fork();

	 if(pid < 0) { /* error occured */
	    fprintf(stderr, "fork failed");
			return 1;
		}
	  else if(pid == 0){/* child process*/
		  execlp("/bin/ls","ls",NULL);
			printf("LINE J");
		}else{/* parent process*/
		   /* parent will wait for the child to complete*/
			 wait(NULL);
			 printf("Child complete);
		}
			   return 0;
				 
}

a)If an error occurs in the call to exec()
b)If the call to exec succeeds
c)Line J always runs
d)Line J never runs under normal conditions (e.g. abnormal condition is if the cmd does not exist)
e)A and D

A

E

E - A and D
A If an error occurs in exec, like command is invalid, it will go to next line
D Exec will replace the memory if it succeeds

82
Q

A process can be terminated due to __________
a)normal exit
b)fatal error
c)killed by another process
d)all of the mentioned

A

D

D Anything can terminate a process, though all signals can be handled in code

82
Q

lecture 5 slide 39

A

A

83
Q

lecture 5 slide 42

A

A

The values output by the parent at line Y are 0, 1, 2, 3, 4.

84
Q

What is interprocess communication (IPC)?
a) communication within the process
b) communication between two process
c) communication between two threads of same process
d) none of the mentioned

A

B

IPC involves 2 processes

85
Q

Run the code under Canvas code/ipc/parent_child_pipe.c. What does it do?
a. It makes a pipe between 2 processes.
b. It executes commands from the user in forked processes.
c. Child sends a string to parent through a pipe.
d. One process takes a string from stdin and sends it to the other process, which appends it to another string and prints it.
e. Both a and c

A

E

86
Q

Which of the following are true in the case of a pipe as a mechanism of IPC?
A. A pipe is for uni-directional communication.
B. A pipe uses a buffer and the size of the buffer can be specified by the user.
C. Pipes can not support broadcast.
D. All of the above

A

D

http://networklabktu.blogspot.com/2018/01/inter-process-communicationipc-using.html
c. Pipes can be extended to establish communication between processes resident on different machines provided we use the process id together with IP address of the machines.

87
Q

When a pipe is defined – its either end can be utilized freely for reading / writing
a. True
b. False

A

B false

B - One end is for reading and the other is for writing
The read end [0] is opened using the READONLY flag
The write end [1] is opened using the WRITEONLY flag

88
Q

For IPC communication the OS employs an internally defined buffer data-structure, which is defined:
A. In user space
B. As a separate area which is neither in user space nor in kernel space
C. In kernel space

A

C

C - buffer is in kernel space and managed by the OS kernel

89
Q

Why are pipes better than using temporary files (on the hard disk) for IPC?
1. pipes are implemented in memory (RAM), which is faster than disk.
1. with files would have to wait for a file to be completely written (fflush) before next step
1. programs can produce lots of I/O, so better to run them concurrently rather than wait for one to finish before starting the next one
1. you might fill up the disk with large intermediate files or fill your inode quota with too many files
1. all of these are reasons

A

all of these are reasons

E - temporary files on the file system are not good for buffers

90
Q

Which of the following is true in the context of Inter-process communication:
A. It is like a user defined procedure call.
B. It is like user defined a function call.
C. It is a system call (provided by the kernel)
D. None of the above

A

C

C - it needs advanced privileges
https://www.geeksforgeeks.org/pipe-system-call/
https://linuxhint.com/pipe_system_call_c/

91
Q

Run the code under Canvas code/ipc/pipe1.c (from APUE ipc1). What does it do?
A. It makes a pipe between 2 processes.
B. It executes commands from the user in forked processes.
C. It sends a string “hello world” from parent to child through a pipe.
D. It pipes a given file through /bin/more, so the user can scroll through it.
E. Both a and c

A

E

92
Q

Run the code under Canvas code/ipc/fork_pipe.c. What does it do?
A. It makes 2 pipes between parent and child processes.
B. It executes commands from the user in forked processes.
C. It sends a string from parent to child through a pipe.
D. One process takes a string from stdin and sends it to the other process, which appends it to another string and sends it back to be printed.
E. A, C and D

A

E

E-A C D
The C library function size_t strlen(const char *str) computes the length of the string str up to, but not including the terminating null character
https://www.tutorialspoint.com/c_standard_library/c_function_strlen.htm

93
Q

Run the code under Canvas code/ipc/pipe2.c (from APUE ipc1). What does it do?
a. It makes a pipe between 2 processes (parent and a child).
b. It executes commands from the user in forked processes.
c. It sends a string “hello world” from parent to child through a pipe.
d. It pipes a given file through /bin/more, so the user can scroll through it.
e. Both a and d

A

E

94
Q

Run the code under Canvas code/ipc/connect2.c. What does it do?
A. It makes a pipe between 2 child processes.
B. It executes commands from the user in forked processes.
C. It sends a string from parent to child through a pipe.
D. One process takes a string from stdin and sends it to the other process, which appends it to another string and prints it.
E. Both A and B

A

E

95
Q

Run the code under Canvas code/ipc/mcopy2.c (it is from APUE src advio directory). What does it do?
* Copies a file from src to dest using mmap
* Copies a file from src to dest using message passing
* Prints “Hello World”
* Concatenates 2 strings
*

A

Copies a file from src to dest using mmap

96
Q

Memory-mapped files may continue to exist in the system after the creating process has terminated.
True
False

A

True

A One of the benefits of mmap is they can exist even after a process ends

97
Q

Which of the following statements is true?
A) Memory mapping (mmap) allows bi-directional communication between processes.
B) Only the parent and child processes can use memory mapping (mmap) for communication.
C) Reading & writing to ordinary pipes on UNIX systems is performed exactly as file I/O with the Hark Disk Drive.
D) Pipes/sockets can only be used by communicating processes on the same machine.

A

A

A
In the sense that you use file descriptors for the input and output of a pipe, choice “C” also has a valid point. But pipes don’t write to the filesystem like mmap is doing. Pipe data is stored in memory buffers and not written to the filesystem.

98
Q

When a process creates a new process using the fork() operation, which of the following states is shared between the parent process and the child process?
a. Stack
b. Heap
c. Shared memory segments
d. None of the above

A

C

C
Only the shared memory segments are shared between the parent process and the newly forked child process. Copies of the stack and the heap are made for the newly created process

99
Q

Shared memory is a more appropriate IPC mechanism than message passing (e.g. sockets) for distributed systems.
True
False

A

False