Courseiva

CCNA Interprocess Communication Questions

33 questions · Interprocess Communication · All types, answers revealed

1
MCQhard

What is the primary purpose of the subprocess.PIPE constant?

A.To terminate the child process.
B.To speed up subprocess execution.
C.To create a channel for data transfer.
D.To close the standard input.
E.To redirect output to a file.
AnswerC

PIPE enables interaction with the process streams.

Why this answer

It is used to indicate that a new pipe to the child process should be created for stdout or stdin.

2
MCQeasy

Which module allows you to run external programs and interact with their input/output streams?

A.sys
B.subprocess
C.multiprocessing
D.os
E.threading
AnswerB

Subprocess is the standard for managing processes.

Why this answer

The subprocess module is the recommended way to spawn new processes and connect to their pipes.

3
MCQmedium

You are using a multiprocessing.Semaphore(3). What happens when the 4th process attempts to acquire the semaphore?

A.It blocks until a slot is released.
B.It creates a new process slot.
C.It raises an exception.
D.It bypasses the lock.
E.It is terminated by the OS.
AnswerA

This is the standard behavior for a semaphore.

Why this answer

The 4th process will block until one of the previous three processes releases the semaphore.

4
MCQeasy

You are writing a Python script that needs to perform heavy I/O-bound tasks concurrently. Which module should you prioritize to minimize the overhead of global interpreter lock (GIL) contention?

A.queue
B.threading
C.subprocess
D.asyncio
E.multiprocessing
AnswerB

Threading is efficient for I/O-bound tasks because it allows concurrent waiting.

Why this answer

The threading module is ideal for I/O-bound tasks as it releases the GIL during blocking operations, whereas multiprocessing is better for CPU-bound tasks.

5
MCQeasy

If you want to run a function in a background thread, which class should you instantiate?

A.threading.Thread
B.threading.Process
C.subprocess.Thread
D.multiprocessing.Thread
E.thread.Task
AnswerA

The Thread class is for spawning threads.

Why this answer

The threading.Thread class is the standard way to create threads.

6
MCQeasy

Which object would you use to share a simple integer between processes that is safe for concurrent access?

A.list
B.threading.Lock
C.multiprocessing.Value
D.global variable
E.multiprocessing.Queue
AnswerC

Value provides shared memory access to a variable.

Why this answer

multiprocessing.Value is designed specifically to share single values between processes with a lock.

7
Multi-Selectmedium

Which TWO of the following scenarios are best suited for the subprocess module?

Select 2 answers
A.Sharing memory between Python threads.
B.Running an external C++ executable.
C.Managing internal thread pools.
D.Capturing the stdout of a command-line tool.
E.Parallelizing Python functions.
AnswersB, D

Executing external binaries is a primary use case.

Why this answer

Subprocess is intended for executing external binaries and interacting with their system streams.

8
MCQhard

When using a multiprocessing.Queue to share data between processes, what happens if the queue is full and you use the put() method without a timeout?

A.It restarts the child process.
B.It blocks indefinitely until a slot becomes available.
C.It raises a Full exception immediately.
D.It silently drops the data.
E.It overwrites the oldest item in the queue.
AnswerB

Default behavior of put() is to block if the queue is full.

Why this answer

By default, put() is a blocking operation that will wait until a slot is available if the queue is full.

9
MCQhard

You have a thread waiting on a threading.Event. Which method should another thread call to wake up the waiting thread?

A.notify()
B.trigger()
C.start()
D.signal()
E.set()
AnswerE

Set() triggers the Event.

Why this answer

The set() method sets the internal flag to true, causing wait() to return.

10
MCQhard

When using the multiprocessing module, why is it recommended to use a Manager object instead of a standard dictionary to share data between processes?

A.It is faster than standard dictionaries.
B.It is the only way to store strings.
C.It removes the need for locks.
D.It allows local storage of values.
E.It ensures the dictionary is synchronized between processes.
AnswerE

The manager provides a proxy that handles the necessary IPC.

Why this answer

A manager process is created to host the objects, allowing them to be shared safely between different processes using proxy objects.

11
MCQeasy

Which of the following is true regarding daemon threads in Python?

A.They are only used for system-level tasks.
B.They are guaranteed to finish before the program ends.
C.They are abruptly terminated when the main process exits.
D.They use more memory than regular threads.
E.They cannot create child threads.
AnswerC

Daemon threads are force-stopped by the interpreter.

Why this answer

Daemon threads are terminated abruptly when the main program exits, which can lead to incomplete operations.

12
Multi-Selectmedium

Which TWO of the following are key benefits of using the multiprocessing.Pool class?

Select 2 answers
A.Higher performance for I/O tasks than threads.
B.Automatic process creation and management.
C.Guaranteed memory sharing between processes.
D.Automatic elimination of the GIL.
E.Simplified data return with map/starmap methods.
AnswersB, E

Pool manages the process lifecycle.

Why this answer

Pools simplify process management and provide convenient result retrieval mechanisms.

13
Multi-Selecteasy

Which THREE of the following represent types of IPC provided by the multiprocessing module?

Select 3 answers
A.Pipe
B.Queue
C.Thread
D.Global
E.Manager
AnswersA, B, E

Pipes provide a connection between two processes.

Why this answer

Multiprocessing provides Pipes, Queues, and Managers for inter-process communication.

14
Multi-Selectmedium

Which THREE of the following represent ways to synchronize access to shared data in a multi-threaded application?

Select 3 answers
A.threading.Lock
B.threading.System
C.threading.Semaphore
D.threading.Process
E.threading.Event
AnswersA, C, E

Locks provide exclusive access.

Why this answer

Locks, Semaphores, and Events are core tools for controlling access and state between threads.

15
MCQmedium

You are using the subprocess.run() function to execute an external command. Which argument ensures that the command's stdout is captured as a string rather than printed to the console?

A.capture_output=True
B.text=True
C.stdout=True
D.shell=True
E.pipe=True
.redirect=True
AnswerA

This captures standard output and error automatically.

Why this answer

Setting capture_output=True automatically sets stdout and stderr to subprocess.PIPE.

16
MCQmedium

When using subprocess.Popen, why is it dangerous to use shell=True with user-supplied input?

A.It prevents capturing stderr.
B.It slows down execution significantly.
C.It crashes the Python interpreter.
D.It leads to shell command injection vulnerabilities.
E.It forces the use of hardcoded paths.
AnswerD

Executing arbitrary shell commands is a major security flaw.

Why this answer

It introduces a command injection vulnerability where a user can execute arbitrary shell commands.

17
MCQmedium

When spawning processes on Windows, what is the default start method used by the multiprocessing module?

A.thread
B.exec
C.forkserver
D.fork
E.spawn
AnswerE

Spawn is the default on Windows.

Why this answer

The 'spawn' method is the default on Windows.

18
MCQhard

Two threads are modifying a shared global integer. You want to ensure that only one thread modifies the integer at a time. Which synchronization primitive is most appropriate?

A.threading.Lock
B.threading.Event
C.multiprocessing.Semaphore
D.multiprocessing.Queue
E.threading.Condition
AnswerA

A Lock provides the necessary mutual exclusion for threads.

Why this answer

A Lock (or Mutex) is the standard tool to ensure mutually exclusive access to a shared resource.

19
Multi-Selecthard

Which THREE of the following are true about the 'subprocess' module's interaction with the operating system?

Select 3 answers
A.It can connect to standard input/output pipes.
B.It automatically cleans up zombie processes.
C.It allows direct manipulation of the parent process's memory.
D.It can change the current working directory of the child.
E.It can set the environment variables for the child process.
AnswersA, D, E

The stdin/stdout arguments allow this.

Why this answer

Subprocess allows control over pipes, environments, and working directories for child processes.

20
Multi-Selecthard

Which TWO of the following are potential issues when using the 'fork' start method in multiprocessing?

Select 2 answers
A.Threads present in the parent may not be safe in the child.
B.Child processes inherit the parent's file descriptors.
C.It cannot share data at all.
D.It crashes on all Unix systems.
E.It is always slower than spawn.
AnswersA, B

Threads are often broken in the child process after a fork.

Why this answer

Forking a process inherits the parent's memory, which can lead to issues with locks and threads.

21
MCQmedium

Which of the following describes the difference between Process.terminate() and Process.kill()?

A.There is no difference.
B.Terminate() sends SIGTERM, while kill() sends SIGKILL.
C.Terminate() is for threads.
D.Terminate() is more immediate than kill().
E.Kill() is only available on Windows.
AnswerB

SIGTERM allows cleanup, SIGKILL does not.

Why this answer

On most POSIX systems, terminate() sends SIGTERM (polite), while kill() sends SIGKILL (immediate).

22
Multi-Selectmedium

Which THREE of the following features are common to both the threading and multiprocessing modules?

Select 3 answers
A.The start() method to begin execution.
B.Direct access to the GIL.
C.The join() method to wait for completion.
D.Automatic shared memory.
E.The Lock class for synchronization.
AnswersA, C, E

Both classes use start().

Why this answer

Both modules provide mechanisms for joining, starting, and using locks for synchronization.

23
MCQmedium

You are using Pool.apply_async(). How do you retrieve the result of the function call?

A.Wait for the function to return.
B.Use the join() method on the pool.
C.Pass a callback function.
D.Call the get() method on the returned object.
E.Check the pool's result list.
AnswerD

Get() retrieves the result of the asynchronous task.

Why this answer

The apply_async method returns an AsyncResult object, and you must call the get() method on it.

24
MCQmedium

Why should you use a 'with' statement when using a Lock?

A.It allows multiple threads to acquire the lock.
B.It automatically handles lock acquisition and release.
C.It increases the performance of the lock.
D.It creates a thread-safe environment.
E.It prevents the lock from being garbage collected.
AnswerB

It ensures the lock is released reliably.

Why this answer

It automatically acquires and releases the lock, ensuring it is released even if an exception occurs.

25
MCQhard

You are managing subprocesses using subprocess.Popen. Which attribute of the Popen object should you check to verify the exit code after the process terminates?

A.returncode
B.code
C.status
D.poll()
E.exit_code
AnswerA

Returncode holds the exit status of the process.

Why this answer

The returncode attribute is populated after the process finishes or wait() is called.

26
Multi-Selecteasy

Which THREE of the following are valid ways to instantiate a process in the multiprocessing module?

Select 3 answers
A.Using the multiprocessing.Queue method.
B.By subclassing multiprocessing.Process.
C.Passing a target function to Process constructor.
D.Using the threading.Thread class.
E.Direct instantiation of multiprocessing.Process.
AnswersB, C, E

Subclassing is a valid design pattern.

Why this answer

Process can be instantiated directly, via target function, or by subclassing.

27
MCQmedium

You are using the multiprocessing.Process class and notice that child processes are not terminating cleanly. Which method should you call to ensure the main process waits for the child process to complete?

A.process.join()
B.process.wait()
C.process.terminate()
D.process.close()
E.process.is_alive()
AnswerA

Join() is the correct method to synchronize process completion.

Why this answer

The join() method blocks the calling thread until the process whose join() method is called terminates.

28
MCQhard

What is the result of using a Pipe to communicate between two processes if both processes attempt to write to the same end simultaneously?

A.It raises an exception.
B.The OS serializes the writes automatically.
C.The write blocks until the other finishes.
D.One of the writes is silently dropped.
E.The data may be corrupted or interleaved.
AnswerE

Pipes are not inherently thread-safe for concurrent writes.

Why this answer

Data corruption can occur as the messages may become interleaved or mangled.

29
MCQeasy

What is the primary reason to use the multiprocessing module instead of the threading module for CPU-bound tasks in Python?

A.Threading cannot handle files.
B.Multiprocessing is faster for I/O.
C.Threading does not support locks.
D.Multiprocessing bypasses the Global Interpreter Lock (GIL).
E.Threading is deprecated.
AnswerD

Each process has its own Python interpreter and its own GIL.

Why this answer

Because of the Global Interpreter Lock (GIL), multiple threads cannot execute Python bytecode simultaneously on multiple cores.

30
Multi-Selecteasy

Which TWO of the following are valid ways to synchronize threads?

Select 2 answers
A.threading.Semaphore
B.threading.ProcessPool
C.threading.Queue
D.threading.Process
E.threading.Lock
AnswersA, E

Semaphores limit concurrent access.

Why this answer

Locks and Semaphores are fundamental threading synchronization primitives.

31
Multi-Selecthard

Which TWO of the following are true about the multiprocessing.Queue object?

Select 2 answers
A.It is safe to use between processes.
B.It allows direct memory access between processes.
C.It is safe to use between threads.
D.It is slower than a standard Python list.
E.It requires an external database to function.
AnswersA, C

Queues are process-safe.

Why this answer

Queues are thread-safe and process-safe, and they use internal locks and pipes.

32
MCQhard

You are using a multiprocessing.Pool. Which method should you use to apply a function to a sequence of items and get the results back in order as they complete?

A.apply()
B.map_async()
C.imap()
D.map()
E.starmap()
AnswerC

Imap() yields results as they become available, in order.

Why this answer

imap() returns an iterator that yields results in the order of the inputs.

33
MCQeasy

In the context of the threading module, what does the daemon flag do when set to True?

A.It increases the thread's priority.
B.It prevents the thread from being interrupted.
C.It allows the thread to be killed by the OS.
D.It causes the thread to exit when the main process exits.
E.It ensures the thread completes before the program exits.
AnswerD

This is the definition of a daemon thread.

Why this answer

Daemon threads exit automatically when the main program finishes.

Ready to test yourself?

Try a timed practice session using only Interprocess Communication questions.