1Which system call is used to create an unnamed pipe in Unix-like operating systems?
A.open()
B.shmget()
C.pipe()
D.mkfifo()
Correct Answer: pipe()
Explanation:
The pipe() system call creates a unidirectional data channel that can be used for inter-process communication. It creates an unnamed pipe.
Incorrect! Try again.
2When calling int pipe(int fd[2]), what does fd[0] represent?
A.The read end of the pipe
B.The status code
C.The process ID of the child
D.The write end of the pipe
Correct Answer: The read end of the pipe
Explanation:
In the array returned by pipe(), index 0 (fd[0]) refers to the read end of the pipe, and index 1 (fd[1]) refers to the write end.
Incorrect! Try again.
3Which of the following describes the data flow in a standard unnamed pipe?
A.Random Access
B.Circular
C.Bidirectional (Full Duplex)
D.Unidirectional (Half Duplex)
Correct Answer: Unidirectional (Half Duplex)
Explanation:
Standard unnamed pipes allow data to flow in only one direction. Data is written to one end and read from the other.
Incorrect! Try again.
4Unnamed pipes can typically only be used for communication between which types of processes?
A.Processes that have a parent-child or common ancestor relationship
B.Any two processes on the same system, even if unrelated
C.Only between a process and the kernel
D.Any two processes on the network
Correct Answer: Processes that have a parent-child or common ancestor relationship
Explanation:
Because unnamed pipes do not have a name in the filesystem, the file descriptors must be inherited from a parent process via fork().
Incorrect! Try again.
5What happens if a process attempts to write to a pipe that has been full?
A.The write() call blocks until sufficient space is available
B.The write() call fails with an error immediately
C.The pipe size is automatically expanded on disk
D.The data is discarded
Correct Answer: The write() call blocks until sufficient space is available
Explanation:
If the pipe buffer is full, the process writing to it is put to sleep (blocked) by the OS until the reading process removes some data.
Incorrect! Try again.
6Which signal is generated if a process attempts to write to a pipe for which the read end has been closed?
A.SIGPIPE
B.SIGSEGV
C.SIGKILL
D.SIGINT
Correct Answer: SIGPIPE
Explanation:
The kernel sends the SIGPIPE signal to a process that tries to write to a pipe with no readers (broken pipe).
Incorrect! Try again.
7What is the return value of read() from a pipe when the write end has been closed and all data has been read?
A.EOF
B.1
C.0
D.-1
Correct Answer: 0
Explanation:
A return value of 0 from read() indicates the End-of-File (EOF), meaning the writer has closed the connection and no data remains.
Incorrect! Try again.
8In a C program using pipe(fd), how should the parent process configure the file descriptors if it intends to write to the child?
A.Close fd[1] and write to fd[0]
B.Close fd[0] and write to fd[1]
C.Close both and use shared memory
D.Keep both open and write to fd[1]
Correct Answer: Close fd[0] and write to fd[1]
Explanation:
To ensure proper EOF handling and resource management, the parent should close the unused read end (fd[0]) and write data to the write end (fd[1]).
Incorrect! Try again.
9Which library function creates a pipe, forks a child, and invokes the shell to run a command?
A.system()
B.mkfifo()
C.popen()
D.exec()
Correct Answer: popen()
Explanation:
popen() is a high-level library function that handles the creation of the pipe, forking, and executing a command, returning a file pointer.
Incorrect! Try again.
10What guarantees does the OS provide regarding write atomicity for pipes?
A.Writes are never atomic
B.Writes up to PIPE_BUF bytes are atomic
C.All writes, regardless of size, are atomic
D.Only writes of exactly 1 byte are atomic
Correct Answer: Writes up to PIPE_BUF bytes are atomic
Explanation:
If multiple processes write to the same pipe, writes of size up to PIPE_BUF are guaranteed not to be interleaved.
Incorrect! Try again.
11Unlike unnamed pipes, Named FIFOs (First-In-First-Out) exist as:
A.Special device files in the filesystem
B.Variables in the kernel memory only
C.Network sockets
D.Threads within a process
Correct Answer: Special device files in the filesystem
Explanation:
Named FIFOs exist as special files in the filesystem, allowing unrelated processes to communicate by referencing the file path.
Incorrect! Try again.
12Which system call is used to create a Named FIFO?
A.shmget()
B.socket()
C.pipe()
D.mkfifo()
Correct Answer: mkfifo()
Explanation:
mkfifo() is the specific system call used to create a FIFO special file.
Incorrect! Try again.
13What permission/mode arguments does mkfifo() accept?
A.Process ID of the owner
B.Memory size in bytes
C.File permission bits (e.g., 0666)
D.None
Correct Answer: File permission bits (e.g., 0666)
Explanation:
mkfifo() takes a pathname and a mode argument (permissions), similar to how files are created.
Incorrect! Try again.
14When opening a FIFO with open(), what is the default behavior if opened for reading (O_RDONLY) while no process has opened it for writing?
A.It returns -1 immediately
B.It creates a new writer process
C.It blocks until a process opens the FIFO for writing
D.It returns a random file descriptor
Correct Answer: It blocks until a process opens the FIFO for writing
Explanation:
By default, opening a FIFO for reading blocks until another process opens it for writing, and vice versa, to synchronize the start of communication.
Incorrect! Try again.
15How can a process open a FIFO without blocking if the other end is not yet open?
A.Use open_async()
B.Set the FIFO size to 0
C.Use the O_NONBLOCK flag in open()
D.It is not possible
Correct Answer: Use the O_NONBLOCK flag in open()
Explanation:
The O_NONBLOCK flag causes the open() call to return immediately rather than waiting for the counterpart process.
Incorrect! Try again.
16Which command line utility can be used to create a named pipe?
A.cat
B.mkfifo
C.mkdir
D.touch
Correct Answer: mkfifo
Explanation:
The mkfifo command in the shell is a wrapper around the mkfifo() system call.
Incorrect! Try again.
17How do you remove a named pipe from the filesystem?
A.It is automatically removed when processes exit
B.Using shmdt()
C.Using close()
D.Using rm or unlink()
Correct Answer: Using rm or unlink()
Explanation:
Since a named pipe is a file, it persists until explicitly deleted using the rm command or unlink() system call.
Incorrect! Try again.
18Is the data written to a Named FIFO stored permanently on the disk?
A.No, the data is held in kernel buffers and passes to the reader
B.Yes, it acts exactly like a text file
C.No, it is stored in the CPU registers
D.Yes, but only if the buffer overflows
Correct Answer: No, the data is held in kernel buffers and passes to the reader
Explanation:
Although the FIFO has a name in the filesystem, the data itself is passed through kernel buffers and is not written to the hard drive storage permanently.
Incorrect! Try again.
19Which of the following IPC mechanisms is generally considered the fastest?
A.Sockets
B.Shared Memory
C.Message Queues
D.Pipes
Correct Answer: Shared Memory
Explanation:
Shared memory is the fastest because it avoids copying data between user space and kernel space; processes access the same physical memory directly.
Incorrect! Try again.
20In System V IPC, which function is used to create or locate a shared memory segment?
A.shmget()
B.shmat()
C.shm_open()
D.malloc()
Correct Answer: shmget()
Explanation:
shmget() (Shared Memory Get) is used to obtain an identifier for a System V shared memory segment.
Incorrect! Try again.
21The key argument in shmget() is typically generated using which function to ensure a unique identifier?
A.time()
B.rand()
C.ftok()
D.getpid()
Correct Answer: ftok()
Explanation:
ftok() (File to Key) generates a System V IPC key based on a pathname and a project identifier.
Incorrect! Try again.
22What is the return value of shmget() on success?
A.A pointer to the memory
B.Zero
C.A non-negative integer (Shmid)
D.The size of the memory created
Correct Answer: A non-negative integer (Shmid)
Explanation:
shmget() returns the Shared Memory Identifier (shmid), which is used in subsequent calls like shmat and shmctl.
Incorrect! Try again.
23Which function is used to attach a shared memory segment to the address space of the calling process?
A.shmget()
B.mmap()
C.shmdt()
D.shmat()
Correct Answer: shmat()
Explanation:
shmat() (Shared Memory Attach) maps the shared segment into the process's data space.
Incorrect! Try again.
24What does shmat() return on success?
A.0
B.The shmid
C.The number of processes attached
D.A pointer (void *) to the attached memory segment
Correct Answer: A pointer (void *) to the attached memory segment
Explanation:
shmat() returns the virtual address at which the shared memory segment has been mapped.
Incorrect! Try again.
25When a process finishes using a shared memory segment, which function should it call to detach it?
A.shmdt()
B.delete()
C.free()
D.shmrem()
Correct Answer: shmdt()
Explanation:
shmdt() (Shared Memory Detach) detaches the shared memory segment from the address space of the calling process.
Incorrect! Try again.
26Does calling shmdt() destroy the shared memory segment in the kernel?
A.No, unless the IPC_RMID flag was set during creation
B.No, it only detaches it from the current process
C.Yes, immediately
D.Yes, if no other processes are attached
Correct Answer: No, it only detaches it from the current process
Explanation:
shmdt() only removes the mapping for the calling process. The segment remains in the OS until explicitly removed via shmctl().
Incorrect! Try again.
27Which function is used to perform control operations, such as removing a shared memory segment?
A.ioctl()
B.shmctl()
C.shmget()
D.shm_unlink()
Correct Answer: shmctl()
Explanation:
shmctl() allows the user to perform control operations, including retrieving status and removing the segment (IPC_RMID).
Incorrect! Try again.
28Which command is used in shmctl() to mark a segment for destruction?
A.IPC_RMID
B.SHM_DEL
C.IPC_SET
D.IPC_STAT
Correct Answer: IPC_RMID
Explanation:
IPC_RMID is the command flag passed to shmctl() to remove the shared memory identifier from the system.
Incorrect! Try again.
29What is the primary synchronization issue associated with Shared Memory?
Because processes access memory simultaneously, the OS does not automatically synchronize access. Without external synchronization (like semaphores), race conditions occur.
Incorrect! Try again.
30Which flag is combined with IPC_CREAT in shmget() to ensure the call fails if the segment already exists?
A.IPC_FORCE
B.IPC_EXCL
C.O_TRUNC
D.IPC_NOWAIT
Correct Answer: IPC_EXCL
Explanation:
Using IPC_CREAT | IPC_EXCL ensures that shmget() creates a new segment and fails if the key is already associated with an existing segment.
Incorrect! Try again.
31Which shell command displays information about active Inter-Process Communication facilities (including shared memory)?
A.lsipc
B.ipcs
C.top
D.ps
Correct Answer: ipcs
Explanation:
ipcs stands for IPC Status and shows information on message queues, shared memory, and semaphores.
Incorrect! Try again.
32Which shell command is used to manually remove an IPC resource like a shared memory segment?
A.ipcrm
B.delshm
C.rm
D.kill
Correct Answer: ipcrm
Explanation:
ipcrm allows users to remove IPC objects (shared memory, semaphores, queues) from the command line using IDs or keys.
Incorrect! Try again.
33In the context of Shared Memory, what does 'System V Persistence' mean?
A.Memory persists until the system is rebooted or explicitly deleted
B.Memory persists only while the creating process is alive
C.Memory is cleared every time a context switch occurs
D.Memory persists permanently on the hard drive
Correct Answer: Memory persists until the system is rebooted or explicitly deleted
Explanation:
System V IPC objects have kernel persistence; they remain until removed by a process or a system reboot.
Incorrect! Try again.
34What is the approximate size limit of a pipe buffer on Linux (modern defaults)?
A.64 KB
B.Unlimited
C.1 byte
D.1 GB
Correct Answer: 64 KB
Explanation:
While it varies by OS and configuration, modern Linux defaults typically set the pipe buffer size to 64 KB (16 pages).
Incorrect! Try again.
35Which system call allows a process to duplicate a file descriptor (often used to redirect stdout to a pipe)?
A.copy()
B.dup2()
C.replic()
D.clone()
Correct Answer: dup2()
Explanation:
dup2(oldfd, newfd) duplicates a file descriptor, allowing redirection (e.g., making stdout 1 point to the write end of a pipe).
Incorrect! Try again.
36If shmat() fails, it returns a pointer with the value:
A.0xDEADBEEF
B.NULL
C.Undefined
D.(void *) -1
Correct Answer: (void *) -1
Explanation:
Unlike malloc which returns NULL, shmat typically returns (void *) -1 on error.
Incorrect! Try again.
37In the POSIX shared memory API (an alternative to System V), which function creates a shared memory object?
A.shm_open()
B.open()
C.fopen()
D.shmget()
Correct Answer: shm_open()
Explanation:
POSIX shared memory uses shm_open() to create or open a shared memory object, which returns a file descriptor.
Incorrect! Try again.
38When using pipe(p), p[1] is closed by the reader process. What is the primary reason for this?
A.To allow the writer to write faster
B.To save memory
C.To prevent the reader from hanging waiting for EOF
D.It is required by syntax
Correct Answer: To prevent the reader from hanging waiting for EOF
Explanation:
If the reader keeps the write end open, read() will never return 0 (EOF) because the OS sees that a write end is still active (even if it belongs to the reader itself).
Incorrect! Try again.
39A FIFO is also known as:
A.Message Queue
B.Unnamed Pipe
C.Socket Pair
D.Named Pipe
Correct Answer: Named Pipe
Explanation:
Named FIFOs are commonly referred to as Named Pipes.
Incorrect! Try again.
40Which header file is primarily required for shmget and shmat?
A.<unistd.h>
B.<sys/shm.h>
C.<sys/socket.h>
D.<stdio.h>
Correct Answer: <sys/shm.h>
Explanation:
<sys/shm.h> (along with <sys/ipc.h>) defines the System V shared memory structures and constants.
Incorrect! Try again.
41If a process calls fork() after creating a shared memory segment but before attaching it:
A.The child inherits the shared memory ID (shmid)
B.The fork fails
C.The segment is deleted
D.The child automatically attaches to it
Correct Answer: The child inherits the shared memory ID (shmid)
Explanation:
The child inherits variables (like the integer shmid) from the parent, so it can use that ID to call shmat() itself.
Incorrect! Try again.
42If a process calls fork() after attaching (shmat) a shared memory segment:
A.The memory becomes private to the parent
B.The OS kills the child
C.The child inherits the attached shared memory segment
D.The child must re-attach manually
Correct Answer: The child inherits the attached shared memory segment
Explanation:
Attached shared memory segments are part of the process address space, which is duplicated (COW) or shared during fork(), so the child has access to the attached memory immediately.
Incorrect! Try again.
43Which error code is set by shmget if IPC_CREAT | IPC_EXCL are set and the segment already exists?
A.EINVAL
B.ENOMEM
C.EEXIST
D.EACCES
Correct Answer: EEXIST
Explanation:
EEXIST indicates that the shared memory identifier already exists for the given key.
Incorrect! Try again.
44What is the relationship between mmap and shared memory?
A.mmap is slower than read/write
B.They are completely unrelated
C.POSIX shared memory uses mmap to map the object into memory
D.mmap is only for files, not shared memory
Correct Answer: POSIX shared memory uses mmap to map the object into memory
Explanation:
In POSIX IPC, after shm_open() gives a file descriptor, mmap() is used to map that descriptor into the process's address space.
Incorrect! Try again.
45Why might mkfifo() fail with EEXIST?
A.The system limit for pipes is reached
B.The process has no permission
C.The pathname already exists
D.The disk is full
Correct Answer: The pathname already exists
Explanation:
If the file name specified in mkfifo() already exists in the directory, it returns EEXIST.
Incorrect! Try again.
46In a producer-consumer problem using shared memory, what additional mechanism is most essential?
Shared memory has no built-in locking. Semaphores are required to prevent the producer from overwriting unread data and the consumer from reading invalid data.
Incorrect! Try again.
47What happens if you try to lseek() on a pipe descriptor?
A.It resets the pipe
B.It fails with ESPIPE
C.It moves the read pointer
D.It works normally
Correct Answer: It fails with ESPIPE
Explanation:
Pipes are streams, not files on a disk with seekable offsets. lseek is not supported and returns the error ESPIPE.
Incorrect! Try again.
48The structure used in shmctl to read/write permissions and ownership is:
A.struct ipc_perm
B.struct shmid_ds
C.struct stat
D.struct file
Correct Answer: struct shmid_ds
Explanation:
struct shmid_ds contains the data structure defining the shared memory segment, including ownership and permissions.
Incorrect! Try again.
49When data is read from a pipe:
A.It creates a new child process
B.It is consumed/removed from the pipe
C.It remains in the pipe for other readers
D.It is copied to a backup file
Correct Answer: It is consumed/removed from the pipe
Explanation:
Pipes are FIFO queues. Once data is read, it is removed from the buffer.
Incorrect! Try again.
50Which standard defines the pipe, shmget, and mkfifo behaviors discussed?
A.HTML5
B.Windows API
C.POSIX / Single UNIX Specification
D.ISO 9001
Correct Answer: POSIX / Single UNIX Specification
Explanation:
These IPC mechanisms are defined by POSIX and the Single UNIX Specification for Unix-like operating systems.