1Which system call is used to create an anonymous pipe in a Unix-like operating system?
A.mkfifo()
B.pipe()
C.shmget()
D.socket()
Correct Answer: pipe()
Explanation:The pipe() system call creates a unidirectional data channel that can be used for inter-process communication.
Incorrect! Try again.
2In the C function int pipe(int fd[2]);, what does fd[0] represent?
A.The write end of the pipe
B.The read end of the pipe
C.The process ID of the creator
D.The size of the pipe buffer
Correct Answer: The read end of the pipe
Explanation:When pipe() is called successfully, fd[0] is assigned the file descriptor for the read end, and fd[1] is assigned the file descriptor for the write end.
Incorrect! Try again.
3Which of the following statements regarding anonymous pipes is TRUE?
A.They can be used for communication between unrelated processes over a network.
B.They persist in the filesystem after the process terminates.
C.They are generally unidirectional (half-duplex).
D.They use shmat() to attach to memory.
Correct Answer: They are generally unidirectional (half-duplex).
Explanation:Standard anonymous pipes allow data to flow in only one direction. To achieve two-way communication, two pipes are typically required.
Incorrect! Try again.
4What happens if a process attempts to write to a pipe for which the read end has been closed?
A.The write blocks until the read end is opened.
B.The process receives a SIGPIPE signal.
C.The data is written but lost.
D.The system throws a segmentation fault.
Correct Answer: The process receives a SIGPIPE signal.
Explanation:If a process writes to a pipe with no active reader, the kernel sends the SIGPIPE signal to the writer. If ignored, the write call fails with EPIPE.
Incorrect! Try again.
5Which system call is used to create a Named Pipe (FIFO)?
A.pipe()
B.mkfifo()
C.open()
D.shm_open()
Correct Answer: mkfifo()
Explanation:The mkfifo() system call creates a named pipe (FIFO) special file in the file system.
Incorrect! Try again.
6What is the primary difference between an anonymous pipe and a named FIFO?
A.FIFOs are faster than pipes.
B.FIFOs allow communication between unrelated processes.
C.Pipes rely on shared memory, while FIFOs do not.
D.Pipes are bidirectional by default, whereas FIFOs are unidirectional.
Correct Answer: FIFOs allow communication between unrelated processes.
Explanation:Anonymous pipes require a parent-child relationship (lineage). Named FIFOs exist as device files in the filesystem, allowing any process with permissions to communicate.
Incorrect! Try again.
7When using Shared Memory, which IPC mechanism is typically defined as the fastest?
A.Message Queues
B.Pipes
C.Shared Memory
D.Sockets
Correct Answer: Shared Memory
Explanation:Shared Memory is generally the fastest IPC because processes read and write directly to the same memory location, avoiding the overhead of copying data between user space and kernel space.
Incorrect! Try again.
8In System V Shared Memory, which system call is used to attach a shared memory segment to the address space of the calling process?
A.shmget()
B.shmat()
C.shmdt()
D.shmctl()
Correct Answer: shmat()
Explanation:shmat() (Shared Memory Attach) attaches the shared memory segment identified by shmid to the address space of the calling process.
Incorrect! Try again.
9What is the return value of the pipe() system call upon failure?
A.
B.1
C.-1
D.NULL
Correct Answer: -1
Explanation:On success, pipe() returns 0. On failure, it returns -1 and sets errno.
Incorrect! Try again.
10Which command line utility allows you to create a named pipe?
A.mkdir
B.mkpipe
C.mkfifo
D.cat
Correct Answer: mkfifo
Explanation:The command mkfifo filename creates a named pipe in the shell.
Incorrect! Try again.
11In the context of Shared Memory, what potential issue must be managed by the programmer using synchronization tools (like semaphores)?
A.Memory leaks
B.Race conditions
C.Buffer overflow
D.Deadlocks only
Correct Answer: Race conditions
Explanation:Since multiple processes access the same memory region simultaneously, race conditions occur if access (read/write) is not synchronized.
Incorrect! Try again.
12Which file type character represents a named pipe in the output of ls -l?
A.-
B.d
C.l
D.p
Correct Answer: p
Explanation:A named pipe is represented by the character p in the file mode field (e.g., prw-r--r--).
Incorrect! Try again.
13What does the shmdt() system call do?
A.Deletes the shared memory segment.
B.Detaches the shared memory segment from the process's address space.
C.Creates a new shared memory segment.
D.Modifies the permissions of the segment.
Correct Answer: Detaches the shared memory segment from the process's address space.
Explanation:shmdt() detaches the shared memory segment located at the address specified from the address space of the calling process.
Incorrect! Try again.
14If a process calls read() on an empty pipe, what happens by default?
A.It returns EOF immediately.
B.It returns -1 immediately.
C.It blocks (waits) until data is written to the pipe.
D.It causes a segmentation fault.
Correct Answer: It blocks (waits) until data is written to the pipe.
Explanation:By default, reading from an empty pipe blocks the process until data is available, unless the write end is closed (sending EOF) or O_NONBLOCK is used.
Incorrect! Try again.
15In System V IPC, which function is often used to generate a unique key (of type key_t) for shmget()?
A.keygen()
B.ftok()
C.getpid()
D.rand()
Correct Answer: ftok()
Explanation:ftok() (File to Key) converts a pathname and a project identifier into a System V IPC key.
Incorrect! Try again.
16Which header file is required for the pipe() system call?
A.<stdio.h>
B.<unistd.h>
C.<sys/shm.h>
D.<stdlib.h>
Correct Answer: <unistd.h>
Explanation:The pipe() system call is defined in <unistd.h>.
Incorrect! Try again.
17When a process forks, how do the child process and parent process handle file descriptors for an existing pipe?
A.The child creates new pipes automatically.
B.The child inherits the file descriptors of the pipe.
C.The child cannot access the parent's pipe.
D.The pipe is destroyed.
Correct Answer: The child inherits the file descriptors of the pipe.
Explanation:Through fork(), the child inherits open file descriptors, including those for the pipe, allowing parent-child communication.
Incorrect! Try again.
18What flag is used in shmget() to ensure a new shared memory segment is created, failing if it already exists?
A.IPC_CREAT
B.IPC_EXCL
C.IPC_CREAT | IPC_EXCL
D.IPC_NOWAIT
Correct Answer: IPC_CREAT | IPC_EXCL
Explanation:Using IPC_CREAT | IPC_EXCL ensures that the call creates a new segment, and returns an error if a segment with the given key already exists.
Incorrect! Try again.
19In POSIX Shared Memory, which function creates or opens a shared memory object?
A.shm_open()
B.shmget()
C.open()
D.mmap()
Correct Answer: shm_open()
Explanation:POSIX shared memory uses shm_open(), whereas System V shared memory uses shmget().
Incorrect! Try again.
20What is the maximum amount of data that can be written atomically to a pipe (guaranteed not to be interleaved) defined by?
A.PIPE_MAX
B.PIPE_BUF
C.BUF_SIZ
D.MAX_INT
Correct Answer: PIPE_BUF
Explanation:Writes of size up to PIPE_BUF are atomic. Writes larger than this may be interleaved with writes from other processes.
Incorrect! Try again.
21Which command allows a user to remove a shared memory segment from the command line?
A.rm
B.ipcrm
C.shmrm
D.delshm
Correct Answer: ipcrm
Explanation:ipcrm is a system utility used to remove System V inter-process communication (IPC) objects, including shared memory.
Incorrect! Try again.
22Why must the unused ends of a pipe be closed in a parent/child process scenario?
A.To save memory.
B.To prevent the process from hanging (EOF detection).
C.To allow bidirectional communication.
D.To clear the buffer.
Correct Answer: To prevent the process from hanging (EOF detection).
Explanation:If a reader keeps the write end open, read() will never return 0 (EOF) because the system thinks a writer is still active, potentially causing the process to hang indefinitely.
Incorrect! Try again.
23Which of the following creates a bidirectional communication channel using standard pipes?
A.Calling pipe() once.
B.Calling pipe() twice to create two pipes.
C.Using mkfifo().
D.Using dup2().
Correct Answer: Calling pipe() twice to create two pipes.
Explanation:Since standard pipes are unidirectional, two pipes are needed for full-duplex communication: one for Parent to Child, and one for Child to Parent.
Incorrect! Try again.
24In System V IPC, shmctl() with the command IPC_RMID performs what action?
A.Detaches the segment.
B.Marks the segment to be destroyed.
C.Changes the permissions.
D.Locks the segment in memory.
Correct Answer: Marks the segment to be destroyed.
Explanation:IPC_RMID marks the segment for destruction. It is actually destroyed only after the last process detaches from it.
Incorrect! Try again.
25Unlike pipes, shared memory does not utilize which of the following OS mechanisms for data transfer?
A.Memory addressing
B.Kernel buffering (copying)
C.File descriptors (in System V)
D.Synchronization primitives
Correct Answer: Kernel buffering (copying)
Explanation:Pipes copy data from user space to kernel buffer and back. Shared memory maps the same physical pages to different processes, bypassing kernel buffering.
Incorrect! Try again.
26Which function maps a POSIX shared memory object into the process's address space?
A.shm_attach()
B.shmat()
C.mmap()
D.map_shared()
Correct Answer: mmap()
Explanation:In POSIX shared memory, shm_open gives a file descriptor, which is then passed to mmap() to map the memory.
Incorrect! Try again.
27What is the typical permission value 0666 in mkfifo("myfifo", 0666) representing?
A.Read/Write for Owner only.
B.Read/Write for Owner, Group, and Others.
C.Execute only.
D.Read only for everyone.
Correct Answer: Read/Write for Owner, Group, and Others.
Explanation:In octal notation, 6 represents Read (4) + Write (2). 0666 grants read and write permissions to User, Group, and Others.
Incorrect! Try again.
28If a FIFO is opened with O_RDONLY, the open() call will block until:
A.The FIFO is empty.
B.Another process opens the FIFO for writing.
C.The process receives a signal.
D.The FIFO is deleted.
Correct Answer: Another process opens the FIFO for writing.
Explanation:Opening a FIFO for reading blocks until another process opens it for writing, and vice-versa, unless O_NONBLOCK is specified.
Incorrect! Try again.
29The library function popen() creates a pipe and performs which other operation?
A.Creates a thread.
B.Forks a child process and invokes a shell.
C.Creates a shared memory segment.
D.Opens a TCP socket.
Correct Answer: Forks a child process and invokes a shell.
Explanation:popen() opens a process by creating a pipe, forking, and invoking the shell to execute a command.
Incorrect! Try again.
30Which function closes the stream opened by popen()?
A.close()
B.fclose()
C.pclose()
D.end()
Correct Answer: pclose()
Explanation:pclose() closes the I/O stream and waits for the child process to terminate.
Incorrect! Try again.
31In the context of shmat(int shmid, const void *shmaddr, int shmflg), if shmaddr is NULL, what does the system do?
A.Returns an error.
B.Attaches to address 0x0.
C.Selects a suitable (unused) address to attach the segment.
D.Uses the address of the stack pointer.
Correct Answer: Selects a suitable (unused) address to attach the segment.
Explanation:If shmaddr is NULL, the kernel chooses a suitable address at which to attach the segment.
Incorrect! Try again.
32Which command displays information about active Shared Memory segments?
A.ls
B.ps -ef
C.ipcs -m
D.netstat
Correct Answer: ipcs -m
Explanation:ipcs provides information on IPC facilities. The -m flag specifically filters for shared memory segments.
Incorrect! Try again.
33What is the effect of the unlink() system call on a FIFO?
A.It deletes the name from the filesystem.
B.It closes the file descriptor.
C.It empties the buffer.
D.It disconnects the writer.
Correct Answer: It deletes the name from the filesystem.
Explanation:unlink() removes the name of the FIFO from the filesystem. The space is reclaimed once all processes have closed it.
Incorrect! Try again.
34When creating a pipe using pipe(fd), fd[1] corresponds to standard output logic (STDOUT_FILENO). Which integer value is typically associated with standard output?
A.
B.1
C.2
D.3
Correct Answer: 1
Explanation:File descriptor 0 is stdin, 1 is stdout, and 2 is stderr.
Incorrect! Try again.
35Which macro is used with shmget() to create a shared memory segment with a key that is guaranteed to be unique (private to the creating process and its children)?
A.IPC_PRIVATE
B.IPC_UNIQUE
C.IPC_CREAT
D.SHM_R
Correct Answer: IPC_PRIVATE
Explanation:Using IPC_PRIVATE as the key guarantees the creation of a new shared memory segment intended for parent-child communication.
Incorrect! Try again.
36What happens if a process tries to write to a full pipe?
A.The data is overwritten.
B.The process is terminated.
C.The write() call blocks until space is available.
D.The write() call returns success without writing data.
Correct Answer: The write() call blocks until space is available.
Explanation:Pipes have a limited capacity (buffer). If full, write() blocks unless the file descriptor is set to non-blocking.
Incorrect! Try again.
37In POSIX shared memory, shm_unlink() serves what purpose?
A.Unmaps the memory.
B.Removes the shared memory object name.
C.Closes the file descriptor.
D.Synchronizes memory.
Correct Answer: Removes the shared memory object name.
Explanation:shm_unlink() removes the name of the shared memory object, similar to unlink() for files.
Incorrect! Try again.
38Which of the following is NOT a valid argument for the shmflg parameter in shmat()?
A.SHM_RDONLY
B.SHM_RND
C.
D.O_CREAT
Correct Answer: O_CREAT
Explanation:O_CREAT is a flag for open(), not shmat(). SHM_RDONLY and SHM_RND are valid flags for shmat.
Incorrect! Try again.
39Data written to a pipe is treated as:
A.A stream of bytes.
B.Structured records.
C.Linked lists.
D.Indexed blocks.
Correct Answer: A stream of bytes.
Explanation:Pipes and FIFOs handle data as an unstructured stream of bytes (byte stream).
Incorrect! Try again.
40To redirect the standard output of a process to a pipe, which system call is most commonly used after pipe() and fork()?
A.assign()
B.dup2()
C.connect()
D.link()
Correct Answer: dup2()
Explanation:dup2(oldfd, newfd) is used to duplicate the pipe's file descriptor to standard output (STDOUT_FILENO).
Incorrect! Try again.
41What is the return type of shmat()?
A.int
B.void *
C.char *
D.struct shmid_ds
Correct Answer: void *
Explanation:shmat returns a pointer (void *) to the attached shared memory segment, or (void *) -1 on error.
Incorrect! Try again.
42In a producer-consumer problem using shared memory, where is the data stored?
A.In the kernel stack.
B.In a file on the disk.
C.In a memory segment accessible by both processes.
D.In the CPU registers.
Correct Answer: In a memory segment accessible by both processes.
Explanation:The shared memory segment resides in physical memory and is mapped into the virtual address space of both the producer and the consumer.
Incorrect! Try again.
43The shmid_ds structure (used with shmctl) contains which information?
A.The actual data of the segment.
B.Permissions, size, and attachment times.
C.The file descriptors of the pipes.
D.The socket addresses.
Correct Answer: Permissions, size, and attachment times.
Explanation:shmid_ds creates a kernel data structure that holds metadata about the shared memory segment, such as ownership, permissions, and timestamps.
Incorrect! Try again.
44Why is read() on a pipe considered a destructive operation?
A.It destroys the pipe.
B.Consumed data is removed from the buffer.
C.It corrupts the file descriptors.
D.It unlinks the file.
Correct Answer: Consumed data is removed from the buffer.
Explanation:Once data is read from a pipe, it is removed from the buffer and cannot be read again.
Incorrect! Try again.
45Which of the following IPC methods requires the kernel to intervene for every data transfer operation (read/write)?
A.Shared Memory
B.Pipes
C.Threads sharing global variables
D.Memory Mapped Files
Correct Answer: Pipes
Explanation:Pipes use read() and write() system calls for data transfer, requiring a context switch to the kernel for every operation. Shared memory accesses data directly via memory instructions.
Incorrect! Try again.
46If you wish to use a pipe to send data from a Parent process to a Child process, which ends should be closed in the Child process?
A.The Read end.
B.The Write end.
C.Both ends.
D.Neither end.
Correct Answer: The Write end.
Explanation:If the Parent writes and the Child reads, the Child must close the unused Write end to ensure EOF functions correctly and to prevent accidental writes.
Incorrect! Try again.
47Which header is primarily required for System V Shared Memory (shmget, shmat)?
A.<sys/ipc.h> and <sys/shm.h>
B.<sys/mman.h>
C.<fcntl.h>
D.<sys/socket.h>
Correct Answer: <sys/ipc.h> and <sys/shm.h>
Explanation:System V shared memory definitions are found in <sys/shm.h>, and IPC keys in <sys/ipc.h>.
Incorrect! Try again.
48What is the typical default capacity of a pipe on modern Linux systems?
A.512 bytes
B.4 KB
C.64 KB
D.1 MB
Correct Answer: 64 KB
Explanation:While it varies by OS version, the default pipe buffer size on modern Linux is typically 65,536 bytes (64 KB).
Incorrect! Try again.
49If mmap() is called with MAP_SHARED, modifications to the memory:
A.Are private to the process.
B.Are visible to other processes mapping the same file.
C.Cause a segmentation fault.
D.Are discarded upon closing.
Correct Answer: Are visible to other processes mapping the same file.
Explanation:MAP_SHARED implies that updates to the mapping are visible to other processes mapping the same region.
Incorrect! Try again.
50How does mkfifo() differ from the shell command mknod?
A.mkfifo() is a library/system call; mknod is a general command (often requiring root) to create special files.
B.mkfifo() creates sockets.
C.mknod is only for directories.
D.There is no difference.
Correct Answer: mkfifo() is a library/system call; mknod is a general command (often requiring root) to create special files.
Explanation:mkfifo specifically creates FIFOs. mknod is a more general tool (and system call) that can create character/block devices and FIFOs.
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.