1/44
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
When a program starts in Unix and C++, how many standard file descriptor ids are already open and ready to use without include files?
stdin (0): standard input, stdout (1), and stderr (2)
What is the freopen function?
freopen takes a filename, a file mode, and a stream to redirect to, allowing redirection of standard I/O streams
Which of the following is true about the differences between the parent and child after a fork() in Unix?
The parent's return value is the child's PID, while the child's return value is 0
What is the return value of a child after a fork?
0
When a fork fails what is the return value?
-1
What is the number of processes after the fork statement executes?
2
How many lines of output will this program produce? fork(); if (fork()) cout << "Hello\n";
2 lines
What is displayed? fork(); cout << "PID: " << getpid() << endl;
Two different PIDs
How many processes are created? for (int i = 0; i < 3; i++) fork();
8 processes
Which of the following statements is NOT true about fork()?
The child and parent share the same PID
After a fork operation is the PID of the parent process always zero?
False
Including the parent, how many processes are created in total? if (fork()) fork();
3 processes
What command (system call) allows multiple file descriptors to point to the same open file table entry?
dup()
What's the file descriptor equivalent of fopen() for streams? (maybe)
open()
What is the total number of processes created (including the original parent process) by the following code? fork(); fork(); fork();
8
Given the following pipe declaration. Which index of the fd array should be used to read from the pipe? int fd[2]; pipe(fd);
fd[0]
Given the following pipe declaration. Which index of the fd array should be used to write from the pipe? int fd[2]; pipe(fd);
fd[1]
Which of the following statements about Unix pipes is NOT true?
Pipes can be used to communicate between unrelated processes
Which of the following statements is true about opening a named pipe (FIFO) in Unix using open()?
Opening a named pipe for reading blocks until another process opens it for writing
When using named pipes (FIFOs) for communication between a client and a server in Unix, which of the following is true?
Both the client and server must open the same named pipe file to communicate
You're given these four operations involved in using a named pipe (FIFO): 1. open() the FIFO 2. read() or write() 3. mkfifo() to create the named pipe 4. unlink() to remove the FIFO file. Which of the following is the correct order to use them?
3 ’ 1 ’ 2 ’ 4
Which of the following best describes the behavior of the execvp() system call in Unix?
Replaces the current process with a new program, using the system PATH to locate the executable
In a socket-based client-server program, do both the client and the server need to know and use the same port number to communicate?
True
Which of the following is the correct order of socket operations in a typical client-side socket program?
socket() ’ connect() ’ send() / write()
Which of the following socket APIs is not typically used in a client socket program?
bind()
Which of the following IPC mechanisms can be used to communicate between processes on different machines over a network?
Sockets
Which of the following is not related to socket mechanisms?
fork()
Sockets can be used to communicate between processes on the same machine.
True
Which is the correct order of socket operations for a server?
socket() ’ bind() ’ listen() ’ accept() ’ write()
Which is the correct order of socket operations for a client? (maybe)
socket() ’ connect() ’ write()
When creating a socket with the parameter SOCK_STREAM, which protocol does it typically use?
TCP
What is the loopback address commonly used in socket programming to allow a client and server to communicate on the same machine?
127.0.0.1
What is the type and limitation of the fourth argument (arg) passed to pthread_create()?
It must be a single void* value (one argument only)
pthreadcreate() sets up a thread configuration, but a separate pthreadstart command must be used to actually start the thread.
False
By default, what does it mean when we say a process has only one thread of control?
A process starts with one thread, but can create multiple threads
To correctly build a C++ application using Pthreads on a Linux/Unix system, you must include pthread.h in the source code and use -pthread in the g++ build command.
True
Which of the following **C++ memory segments is not shared by multiple threads of the same program?
Stack
Threads can improve a program's performance because threads in a process can execute for times that are greater than the time allocated to the process they belong to.
False
What is the purpose of a critical section in a multithreaded program, and how many threads are allowed to enter it at a time when protected by a mutex?
To prevent data races; only one thread may enter at a time
What is used to lock and unlock thread code sections to ensure that only one thread at a time can enter?
Mutex
Which pthread function is used in the main thread to wait for a started thread to complete?
pthread_join()
Which of the following statements about threads is NOT true?
Threads run in completely separate address spaces like processes
Is std::cout thread-safe in C++?
Yes, but output from different threads may still get mixed
Which of the following best describes the Linux operating system?
Preemptive and time-sharing
Which of the following best describes Platform as a Service (PaaS) in cloud computing?
A model where developers deploy and run applications without managing the underlying infrastructure