quizzes and ppt Flashcards

1
Q

What types of sockets are typically used for communication within the same machine?

A

Stream sockets

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

What is the default action when a process receives the SIGINT signal?

A

Terminate the process

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

When might a developer choose to use SIGUSR1 and SIGUSR2 signals for interprocess communication?

A

To request a process to perform a specific action or task

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

What is the primary purpose of standard I/O streams in C programming?

A

To provide an abstraction for file descriptors and buffers

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

In the write() function, what does the count parameter represent?

A

The maximum number of bytes to append to the end of the pipe

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

What does it mean when it’s mentioned that dup2() performs the operation “atomically”?

A

There is no time lapse between closing newfd and duplicating oldfd into its spot

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

Which protocol is commonly used for communication over the internet using sockets?

A

TCP/IP

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

You have an IP address represented as 127.0.0.1 (IPv4) in a human-readable format. Which of the following options correctly represents this IP address in network byte order using the htonl() function in C?

0x0100007F
0x7F000001
0x00000001
0x7F000000

A

0x7F000001

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

In a C program, what does a socket address typically look like when combining an IP address and a port number?

A

A structure, e.g., struct sockaddr_in

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

Identify the function and whether it belongs to the server side process or client side process

recvfrom()

bind()

connect()

accept()

listen()

socket()

A

recvfrom()
both server side and client side

bind()
server side

connect()
client side

accept()
server side

listen()
server side

socket()
both server side and client side

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

Process Control Block (PCB) contains the following information related to a process

A

Process ID

Program Counter

Process Priority

List of open files

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

When a process places an I/O request, it is placed in the

A

I/O Queue

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

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

Considering you don’t have an overloaded machine, how many times will this code print hello :

#include <sys/types.h>
#include <unistd.h>
int main()
{
fork();
fork();
fork();
printf("hello\n");
return 0;
}</unistd.h>

A

8

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

fork() returns a 0 on failure

A

False

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

wait() or sleep() functions can introduce synchronization between concurrently executing processes

A

true

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

Signals can be generated from these sources.

A

hardware, keyboard and C program

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

When a system call is made, the CPU will run in _____________ mode

A

kernel

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

Choose the modes of opening a file

A

O_RDONLY

O_RDWR

O_WRONLY

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

This is a collection of memory locations that a process can access.

A

virtual address space

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

In UNIX/LINUX the file descriptor associated with your monitor or screen or the standard output is ___________

A

1

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

Match the different sections of a process’s user-level context with the corresponding data stored

text

data

heap

stack

A

text
source code

data
static and global variables initialized at runtime

heap
dynamic memory allocated at runtime

stack
return addresses, function parameters, variables etc

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

What is stored in a register during a context switch for a register-level context in processes?

A

The program counter (PC) and some processor status flags

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

What is the primary advantage of using threads in a multi-threaded application?

A

Threads allow for concurrent execution and better resource utilization

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

Which of the following is true about thread synchronization?

A

Thread synchronization is used to ensure that threads do not interfere with each other when accessing shared resources

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

A condition variable is used to wait until a particular condition is true. Condition variables must be used in conjunction with a mutex lock.

A

true

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

Suppose P, Q and R are co-operating processes satisfying Mutual Exclusion condition. If the process Q is executing in its critical section then, ……………..

A

‘P’ does not executes in critical section
‘R’ does not executes in critical section

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

Which are true of the (counting) semaphore operation called “wait()”?

A

it decrements the value of the semaphore

if the value becomes negative, the calling process is blocked

A lower-level mutual exclusion mechanism is needed, to ensure that the fetching and storing of the semaphore value are done atomically.

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

Which of the following are true of the pthread_mutex_lock() operation?

A

it takes a reference to a mutex as a parameter
it is intended to provide mutual exclusion

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

If one thread of a process is holding the lock on a mutex, and another thread of the process attempts to lock the mutex, the whole process is blocked. (t/f)

A

false

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

In a system that supports multithreaded processes, which of the following are likely to be associated with an individual thread (i.e., different for different threads within the process)?

A

Execution state (running, ready, etc.)
Saved context (when not running)
Execution stack
Set of accessible open files

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

Because the thread scheduling algorithm can swap between threads at any time, you must program the order in which the threads will attempt to access the shared data (t/f)

A

false

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

A “strong” semaphore is one that always achieves mutual exclusion. (t/f)

A

true

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

Match the following

Counting Mechanism for Resource Allocation

Used to Coordinate Threads’ Execution

Non-deterministic events

Threads make no progress because of this circular chain of dependency mechanism

An atomic increment and decrement operation is

A

Counting Mechanism for Resource Allocation
Semaphore

Used to Coordinate Threads’ Execution
Condition variables

Non-deterministic events
Spurious wakeup

Threads make no progress because of this circular chain of dependency mechanism
Deadlock

An atomic increment and decrement operation is
Thread-safe

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

Say the critical section is protected by the exitSemaphore. When a thread finishes its critical section, it signals this by calling sem_post(&exitSemaphore) (t/f)

A

true

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

The ___________ function is used to create a socket (communication endpoint) and returns a file descriptor that can be used for further socket operations.

A

socket()

35
Q

After a successful dup2() call, what is the relationship between oldfd and newfd?

A

They refer to the same file

36
Q

When is atomicity guaranteed for the write() operation?

A

For requests with a size typically around 4096 bytes or less

37
Q

What does the pipe() system call return if an error occurs during its execution?

A

-1

38
Q

What is the general syntax of the pipe() system call?

A

int pipe(fd[2]);

39
Q

fputc() is used for buffered character output (it writes a character to a specified file stream and allows buffering for improved performance) but putc() is a more general function and can be used for unbuffered character output or buffered character output depending on the file stream (t/f)

A

true

40
Q

Why is the gets(theBuffer) function considered a high-security risk?

A

It can overwrite memory and lead to buffer overflow vulnerabilities.

41
Q

A thread can be bound to multiple processes. (t/f)

A

false

42
Q

In blocking I/O, a program waits for the operation to complete and can be delayed, potentially causing slower performance. (t/f)

A

true

43
Q

After a successful call to execv (Select all that apply)

A

instructions are executed at the beginning of main()

an executable specified as an argument to execv is loaded

44
Q

A deadlock might occur when one thread tries to send a message from user A to user B while another tries to send a message from user B to user A (t/f)

A

true

45
Q

____________ and ____________ are custom signals that can be used for user-defined purposes, such as triggering specific actions within a process.

A

SIGUSR1 and SIGUSR2

46
Q

ssh and http can be implemented using this socket type.

A

a connection-oriented socket like TCP

47
Q

Select the true statements about stream sockets

Data arrives in the form of a byte-stream

Receiver needs to separate messages in stream

There is no requirement to segment the data into packets.

Data transfer happens using send() and recv() functions

A

Data arrives in the form of a byte-stream

Receiver needs to separate messages in stream

There is no requirement to segment the data into packets.

Data transfer happens using send() and recv() functions

48
Q

What happens in the following code?

unsigned short val = 0x01FF;
printf(“%u\n”,val);

The printed value will be ___________

A

511

49
Q

Which parameter specifies the maximum number of established connections waiting to be accepted (using accept()) in conjunction with the listen() function?

A

backlog

50
Q

Which function translates a host name to an IP address?

A

gethostbyname

51
Q

Choose the correct statements about select().

Waits on multiple file descriptors/sockets and timeout

Application does not consume CPU cycles while waiting

Returns when file descriptors/sockets are ready to be read or written or they have an error or timeout exceeded

Has a disadvantage that it does not scale to large number of file descriptors/sockets

A

(all of them)

Waits on multiple file descriptors/sockets and timeout

Application does not consume CPU cycles while waiting

Returns when file descriptors/sockets are ready to be read or written or they have an error or timeout exceeded

Has a disadvantage that it does not scale to large number of file descriptors/sockets

52
Q

In a C program, when should you use fflush(stdout);?

A

To ensure that any buffered output to the standard output (stdout) is immediately written to the screen.

53
Q

When should IO multiplexing be used?

A

When you need to handle concurrent I/O operations, such as reading from or writing to multiple sockets or files.

54
Q

The following happens in sem_post(sem_t *sem);

sem_post() increments (unlocks) the semaphore pointed to by sem

it returns a zero on success

if the semaphore’s value becomes greater than zero as a result of sem_post() then another thread blocked in a sem_wait() call will be woken up to lock the semaphore

None of the above

A

sem_post() increments (unlocks) the semaphore pointed to by sem

it returns a zero on success

if the semaphore’s value becomes greater than zero as a result of sem_post() then another thread blocked in a sem_wait() call will be woken up to lock the semaphore

55
Q

This signal cannot be ignored or blocked

A

SIGKILL

56
Q

What is the primary purpose of the SIGHUP signal in Unix-like operating systems?

A

Notify a process of changes in terminal status or disconnect

57
Q

Choose the CPU-bound processes among these choices

mathematical computations

image and video processing

file I/O operations

scientific applications

interactive applications that wait for user input

data analysis

A

mathematical computations

image and video processing

scientific applications

data analysis

58
Q

The function of a block special file is to provide access to the hard drive device in fixed-size blocks or chunks, each typically consisting of multiple bytes. (t/f)

A

true

59
Q

What is the primary responsibility of a thread manager in a multithreading environment?

A

Coordinating the creation, scheduling, and termination of threads

60
Q

Consider the following code segment:

int main()

{

if (fork() > 0)

sleep(100);

return 0;

}

Execution of this code could result in the creation of a(n)

A

zombie process

61
Q

<sys/types.h> header defines the various data types used in socket related functions. Choose the common types you encounter here.

ssize_t

socklen_t

size_t

pid_t

A

(all of them)
ssize_t

socklen_t

size_t

pid_t

62
Q

In Unix-like file systems, what does the execute permission (x) on a file indicate for a user?

A

The user can execute the file as a program

63
Q

What is the octal code for granting read and write permissions to the owner, read-only permission to the group, and no permission to others on a file in a Unix-like file system?

A

640

64
Q

Which of the following statements about mutex locks is true?

A

Mutex locks are only used for thread synchronization within a single process

65
Q

A socket system call returns _______ for the created socket

A file descriptor
A process ID
A thread ID
A memory address

A

File descriptor

66
Q

A pthread_create function returns _______ for the newly created thread.

A) A file descriptor
B) A process ID
C) A thread ID
D) A memory address

A

A thread ID

67
Q

A fork() function returns _______ for the newly created process.

A) A file descriptor
B) A process ID
C) A thread ID
D) 0

A

In the parent process, it returns the child’s process ID (PID), and in the child process, it returns 0. On failure, it returns -1.

68
Q

Which of the following statements is true regarding processes and their requirements?

A) A process is the same as an executing program.
B) A process doesn’t require any resources to accomplish its task.
C) A process requires only CPU time to accomplish its task.
D) A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task.

A

A process needs certain resources, including CPU time, memory, files, and I/O devices, to accomplish its task.

69
Q

True or False

If there are no connection requests and the socket is not non-blocking, accept () function blocks till a connection requests comes in.

A

true

70
Q

Which of the following statements is true about long-term scheduler?

A) It is responsible for context switching between processes.
B) It is responsible for selecting processes from memory for execution.
C) It determines which programs are selected for execution from a queue of new processes.
D) It is responsible for allocating memory to processes.

A

C) It determines which programs are selected for execution from a queue of new processes.

71
Q

Which system call associates an address with a socket?

A) bind()
B) connect()
C) listen()
D) accept()

A

Bind()

72
Q

In a client-server networking application, which process typically creates a new child process to handle each incoming client connection?

A) The client process
B) The server process
C) Both the client and server processes
D) Neither the client nor server process

A

The server process

73
Q

Which of the following pieces of information is shared among all threads in a single process?

(A) Heap
(B) Stack
(C) Program Counter (PC)
(D) None of the above.

A

heap

Threads sharethe code and data segments and the heap, but they don’t share the stack.

Stack is for local/method variables & heap is for instance/class variables

74
Q

A process control block should contain ________ .

(A) the process state
(B) a list of open files
(C) the contents of CPU registers
(D) all of the above

A

Process ID

Program Counter

Process Priority

List of open files

75
Q

Context switching between processes is carried out by the________.

job (long-term) scheduler
CPU (short-term) scheduler
interrupt handler
thread manager

A

CPU (short-term) scheduler

76
Q

What are the goals of scheduling?

A

Scheduling goals:

-maximize CPU utilization
-maximize job throughput
-minimize (turnaround time|waiting time|response time)
-batch vs interactive

77
Q

On a typical implementation of POSIX, using read() to read one byte from a file descriptor with a call like:
read(fd, buffer, 1);
where the file descriptor is opened to a file on a hard disk will:

A) cause the OS to request exactly one byte from the disk, then store that byte in the application’s buffer
B) cause read to return an error because the hard disk can only read data in larger blocks
C) cause the OS to request a block of data (larger than one byte) from disk and store it in the OS’s memory, then copy one byte of that into the application’s buffer
D) cause the OS to request a block of data (larger than one byte) from disk, then copy the entire block into the application’s buffer

A

C) cause the OS to request a block of data (larger than one byte) from disk and store it in the OS’s memory, then copy one byte of that into the application’s buffer

78
Q

Port numbers
Select all that apply

A) can be set by bind() in the POSIX socket APIs
B) are assigned only to the end of a connection which calls accept()
C) are typically used by routers to decide where to send messages

A

A) can be set by bind() in the POSIX socket APIs

79
Q

True or False

A race condition occurs when multiple concurrent threads compete to run first. If the thread that wins the race isn’t the one that was supposed to run first, the code may exhibit unexpected behavior. You can resolve this problem with synchronization.

A

true

80
Q

In a multithreaded application, why is thread synchronization needed?

A) To improve thread performance
B) To prevent threads from accessing shared resources simultaneously
C) To reduce the number of threads in the application
D) To prevent threads from crashing the application

A

B) To prevent threads from accessing shared resources simultaneously

81
Q

What is the primary purpose of the exec family of system calls (execl, execv, execve) in Unix-based operating systems?

A) To create a new process
B) To terminate a process
C) To replace the current process with a new process
D) To synchronize access to shared resources between multiple processes

A

C) To replace the current process with a new process

The primary purpose of the exec family of system calls (such as execl, execv, and execve) in Unix-based operating systems is to replace the current process image (i.e., program) with a new process image. This is commonly used to run a different program from within an existing process, such as when a shell script launches a new program. The new program replaces the old program and starts executing from the beginning of its main() function. The exec system calls do not create or terminate processes, nor do they synchronize access to shared resources between processes.

82
Q

A ________ situation occurs when multiple threads are waiting on one another to release CPU resources so they can run.

For example, this can happen when a single thread has exclusive priority but needs resources from a waiting thread, or all the threads are depending on one another to release needed resources.

A

deadlock

83
Q

A _________ is where the current state of a thread or process is stored so the execution of that thread can resume at a later time. This enables a single CPU to manage multiple threads or processes.

A

context switch

84
Q

In a multitasking operating system, what is the main cost associated with context switching between processes?

A) CPU time spent performing the context switch
B) Memory overhead associated with saving and restoring process state
C) Delay incurred in suspending and resuming processes
D) Disk I/O operations required to swap process data to and from memory

A

B) Memory overhead associated with saving and restoring process state