exam 2 practice Flashcards

1
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)

true or false

A

true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
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()

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

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

A

They refer to the same file

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

When is atomicity guaranteed for the write() operation?

A

For requests with a size typically around 4096 bytes or less

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

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

A

-1

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

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

A

int pipe(fd[2]);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
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
true or false

A

True

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

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

A

It can overwrite memory and lead to buffer overflow vulnerabilities.

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

A thread can be bound to multiple processes.

A

False

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

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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
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

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
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

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

ssh and http can be implemented using this socket type.

A

a connection-oriented socket like TCP

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

Select the true statements about stream sockets

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

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

What happens in the following code?

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

The printed value will be ___________

A

511

17
Q

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

A

backlog

18
Q

Which function translates a host name to an IP address?

A

gethostbyname

19
Q

Choose the correct statements about select()

A

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

20
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.

21
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.

22
Q

The following happens in sem_post(sem_t *sem);

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

23
Q

This signal cannot be ignored or blocked

A

SIGKILL

24
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

25
Q

Choose the CPU-bound processes among these choices

A

-mathematical computations
-image and video processing
-scientific applications
-data analysis

26
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.

A

True

27
Q

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

A

Coordinating the creation, scheduling, and termination of threads

28
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

29
Q

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

A

-ssize_t
-socklen_t
-size_t
-pid_t

30
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

31
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

32
Q

Which of the following statements about mutex locks is true?

A

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

33
Q

A socket system call returns _______
for the created socket

A

A file descriptor