exam 2 practice Flashcards
(33 cards)
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
true
The ___________ function is used to create a socket (communication endpoint) and returns a file descriptor that can be used for further socket operations.
socket()
After a successful dup2() call, what is the relationship between oldfd and newfd?
They refer to the same file
When is atomicity guaranteed for the write() operation?
For requests with a size typically around 4096 bytes or less
What does the pipe() system call return if an error occurs during its execution?
-1
What is the general syntax of the pipe() system call?
int pipe(fd[2]);
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
True
Why is the gets(theBuffer) function considered a high-security risk?
It can overwrite memory and lead to buffer overflow vulnerabilities.
A thread can be bound to multiple processes.
False
In blocking I/O, a program waits for the operation to complete and can be delayed, potentially causing slower performance.
True
After a successful call to execv (Select all that apply)
-instructions are executed at the beginning of main()
-an executable specified as an argument to execv is loaded
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
True
____________ and ____________ are custom signals that can be used for user-defined purposes, such as triggering specific actions within a process.
SIGUSR1 and SIGUSR2
ssh and http can be implemented using this socket type.
a connection-oriented socket like TCP
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
What happens in the following code?
unsigned short val = 0x01FF;
printf(“%u\n”,val);
The printed value will be ___________
511
Which parameter specifies the maximum number of established connections waiting to be accepted (using accept()) in conjunction with the listen() function?
backlog
Which function translates a host name to an IP address?
gethostbyname
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
In a C program, when should you use fflush(stdout);?
To ensure that any buffered output to the standard output (stdout) is immediately written to the screen.
When should IO multiplexing be used?
When you need to handle concurrent I/O operations, such as reading from or writing to multiple sockets or files.
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
This signal cannot be ignored or blocked
SIGKILL
What is the primary purpose of the SIGHUP signal in Unix-like operating systems?
Notify a process of changes in terminal status or disconnect