fiunal3

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/44

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

45 Terms

1
New cards

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)

2
New cards

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

3
New cards

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

4
New cards

What is the return value of a child after a fork?

0

5
New cards

When a fork fails what is the return value?

-1

6
New cards

What is the number of processes after the fork statement executes?

2

7
New cards

How many lines of output will this program produce? fork(); if (fork()) cout << "Hello\n";

2 lines

8
New cards

What is displayed? fork(); cout << "PID: " << getpid() << endl;

Two different PIDs

9
New cards

How many processes are created? for (int i = 0; i < 3; i++) fork();

8 processes

10
New cards

Which of the following statements is NOT true about fork()?

The child and parent share the same PID

11
New cards

After a fork operation is the PID of the parent process always zero?

False

12
New cards

Including the parent, how many processes are created in total? if (fork()) fork();

3 processes

13
New cards

What command (system call) allows multiple file descriptors to point to the same open file table entry?

dup()

14
New cards

What's the file descriptor equivalent of fopen() for streams? (maybe)

open()

15
New cards

What is the total number of processes created (including the original parent process) by the following code? fork(); fork(); fork();

8

16
New cards

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]

17
New cards

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]

18
New cards

Which of the following statements about Unix pipes is NOT true?

Pipes can be used to communicate between unrelated processes

19
New cards

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

20
New cards

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

21
New cards

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

22
New cards

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

23
New cards

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

24
New cards

Which of the following is the correct order of socket operations in a typical client-side socket program?

socket() ’ connect() ’ send() / write()

25
New cards

Which of the following socket APIs is not typically used in a client socket program?

bind()

26
New cards

Which of the following IPC mechanisms can be used to communicate between processes on different machines over a network?

Sockets

27
New cards

Which of the following is not related to socket mechanisms?

fork()

28
New cards

Sockets can be used to communicate between processes on the same machine.

True

29
New cards

Which is the correct order of socket operations for a server?

socket() ’ bind() ’ listen() ’ accept() ’ write()

30
New cards

Which is the correct order of socket operations for a client? (maybe)

socket() ’ connect() ’ write()

31
New cards

When creating a socket with the parameter SOCK_STREAM, which protocol does it typically use?

TCP

32
New cards

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

33
New cards

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)

34
New cards

pthreadcreate() sets up a thread configuration, but a separate pthreadstart command must be used to actually start the thread.

False

35
New cards

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

36
New cards

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

37
New cards

Which of the following **C++ memory segments is not shared by multiple threads of the same program?

Stack

38
New cards

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

39
New cards

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

40
New cards

What is used to lock and unlock thread code sections to ensure that only one thread at a time can enter?

Mutex

41
New cards

Which pthread function is used in the main thread to wait for a started thread to complete?

pthread_join()

42
New cards

Which of the following statements about threads is NOT true?

Threads run in completely separate address spaces like processes

43
New cards

Is std::cout thread-safe in C++?

Yes, but output from different threads may still get mixed

44
New cards

Which of the following best describes the Linux operating system?

Preemptive and time-sharing

45
New cards

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