Unit 6: Inter-Process Communication (IPC) - Practice Quiz

CSE325 — Operating Systems Laboratory 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which system call is used to create an unnamed pipe in Unix-like operating systems?

A. pipe()
B. shmget()
C. open()
D. mkfifo()

2 When calling int pipe(int fd[2]), what does fd[0] represent?

A. The process ID of the child
B. The read end of the pipe
C. The write end of the pipe
D. The status code

3 Which of the following describes the data flow in a standard unnamed pipe?

A. Unidirectional (Half Duplex)
B. Random Access
C. Bidirectional (Full Duplex)
D. Circular

4 Unnamed pipes can typically only be used for communication between which types of processes?

A. Any two processes on the same system, even if unrelated
B. Only between a process and the kernel
C. Any two processes on the network
D. Processes that have a parent-child or common ancestor relationship

5 What happens if a process attempts to write to a pipe that has been full?

A. The write() call fails with an error immediately
B. The data is discarded
C. The write() call blocks until sufficient space is available
D. The pipe size is automatically expanded on disk

6 Which 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

7 What is the return value of read() from a pipe when the write end has been closed and all data has been read?

A. 0
B. 1
C. -1
D. EOF

8 In 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 both and use shared memory
B. Close fd[1] and write to fd[0]
C. Keep both open and write to fd[1]
D. Close fd[0] and write to fd[1]

9 Which library function creates a pipe, forks a child, and invokes the shell to run a command?

A. mkfifo()
B. popen()
C. exec()
D. system()

10 What guarantees does the OS provide regarding write atomicity for pipes?

A. Writes are never atomic
B. Only writes of exactly 1 byte are atomic
C. Writes up to PIPE_BUF bytes are atomic
D. All writes, regardless of size, are atomic

11 Unlike unnamed pipes, Named FIFOs (First-In-First-Out) exist as:

A. Variables in the kernel memory only
B. Special device files in the filesystem
C. Network sockets
D. Threads within a process

12 Which system call is used to create a Named FIFO?

A. mkfifo()
B. pipe()
C. socket()
D. shmget()

13 What permission/mode arguments does mkfifo() accept?

A. Memory size in bytes
B. None
C. File permission bits (e.g., 0666)
D. Process ID of the owner

14 When 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 creates a new writer process
B. It returns a random file descriptor
C. It blocks until a process opens the FIFO for writing
D. It returns -1 immediately

15 How can a process open a FIFO without blocking if the other end is not yet open?

A. Use the O_NONBLOCK flag in open()
B. Use open_async()
C. It is not possible
D. Set the FIFO size to 0

16 Which command line utility can be used to create a named pipe?

A. mkdir
B. cat
C. mkfifo
D. touch

17 How do you remove a named pipe from the filesystem?

A. Using close()
B. It is automatically removed when processes exit
C. Using shmdt()
D. Using rm or unlink()

18 Is the data written to a Named FIFO stored permanently on the disk?

A. Yes, it acts exactly like a text file
B. Yes, but only if the buffer overflows
C. No, the data is held in kernel buffers and passes to the reader
D. No, it is stored in the CPU registers

19 Which of the following IPC mechanisms is generally considered the fastest?

A. Pipes
B. Shared Memory
C. Message Queues
D. Sockets

20 In System V IPC, which function is used to create or locate a shared memory segment?

A. shm_open()
B. shmat()
C. shmget()
D. malloc()

21 The key argument in shmget() is typically generated using which function to ensure a unique identifier?

A. rand()
B. getpid()
C. ftok()
D. time()

22 What is the return value of shmget() on success?

A. The size of the memory created
B. A non-negative integer (Shmid)
C. Zero
D. A pointer to the memory

23 Which function is used to attach a shared memory segment to the address space of the calling process?

A. shmdt()
B. shmat()
C. mmap()
D. shmget()

24 What does shmat() return on success?

A. A pointer (void *) to the attached memory segment
B. The number of processes attached
C. The shmid
D. 0

25 When a process finishes using a shared memory segment, which function should it call to detach it?

A. shmdt()
B. shmrem()
C. delete()
D. free()

26 Does calling shmdt() destroy the shared memory segment in the kernel?

A. No, it only detaches it from the current process
B. No, unless the IPC_RMID flag was set during creation
C. Yes, immediately
D. Yes, if no other processes are attached

27 Which function is used to perform control operations, such as removing a shared memory segment?

A. shmget()
B. shm_unlink()
C. ioctl()
D. shmctl()

28 Which command is used in shmctl() to mark a segment for destruction?

A. SHM_DEL
B. IPC_RMID
C. IPC_STAT
D. IPC_SET

29 What is the primary synchronization issue associated with Shared Memory?

A. Race conditions (read/write conflicts)
B. Deadlock only
C. Packet loss
D. Buffer overflow

30 Which flag is combined with IPC_CREAT in shmget() to ensure the call fails if the segment already exists?

A. IPC_EXCL
B. IPC_FORCE
C. IPC_NOWAIT
D. O_TRUNC

31 Which shell command displays information about active Inter-Process Communication facilities (including shared memory)?

A. ps
B. top
C. lsipc
D. ipcs

32 Which shell command is used to manually remove an IPC resource like a shared memory segment?

A. delshm
B. rm
C. ipcrm
D. kill

33 In the context of Shared Memory, what does 'System V Persistence' mean?

A. Memory persists only while the creating process is alive
B. Memory persists until the system is rebooted or explicitly deleted
C. Memory is cleared every time a context switch occurs
D. Memory persists permanently on the hard drive

34 What is the approximate size limit of a pipe buffer on Linux (modern defaults)?

A. Unlimited
B. 64 KB
C. 1 GB
D. 1 byte

35 Which system call allows a process to duplicate a file descriptor (often used to redirect stdout to a pipe)?

A. clone()
B. dup2()
C. replic()
D. copy()

36 If shmat() fails, it returns a pointer with the value:

A. 0xDEADBEEF
B. (void *) -1
C. Undefined
D. NULL

37 In the POSIX shared memory API (an alternative to System V), which function creates a shared memory object?

A. shmget()
B. shm_open()
C. fopen()
D. open()

38 When using pipe(p), p[1] is closed by the reader process. What is the primary reason for this?

A. It is required by syntax
B. To save memory
C. To allow the writer to write faster
D. To prevent the reader from hanging waiting for EOF

39 A FIFO is also known as:

A. Socket Pair
B. Named Pipe
C. Message Queue
D. Unnamed Pipe

40 Which header file is primarily required for shmget and shmat?

A. <sys/socket.h>
B. <sys/shm.h>
C. <unistd.h>
D. <stdio.h>

41 If a process calls fork() after creating a shared memory segment but before attaching it:

A. The segment is deleted
B. The fork fails
C. The child inherits the shared memory ID (shmid)
D. The child automatically attaches to it

42 If a process calls fork() after attaching (shmat) a shared memory segment:

A. The memory becomes private to the parent
B. The child inherits the attached shared memory segment
C. The OS kills the child
D. The child must re-attach manually

43 Which error code is set by shmget if IPC_CREAT | IPC_EXCL are set and the segment already exists?

A. EACCES
B. EEXIST
C. EINVAL
D. ENOMEM

44 What is the relationship between mmap and shared memory?

A. mmap is slower than read/write
B. POSIX shared memory uses mmap to map the object into memory
C. They are completely unrelated
D. mmap is only for files, not shared memory

45 Why 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

46 In a producer-consumer problem using shared memory, what additional mechanism is most essential?

A. Larger hard drives
B. More shared memory
C. Synchronization (e.g., Semaphores)
D. Networking protocols

47 What happens if you try to lseek() on a pipe descriptor?

A. It resets the pipe
B. It moves the read pointer
C. It fails with ESPIPE
D. It works normally

48 The structure used in shmctl to read/write permissions and ownership is:

A. struct ipc_perm
B. struct file
C. struct shmid_ds
D. struct stat

49 When data is read from a pipe:

A. It remains in the pipe for other readers
B. It is consumed/removed from the pipe
C. It is copied to a backup file
D. It creates a new child process

50 Which standard defines the pipe, shmget, and mkfifo behaviors discussed?

A. HTML5
B. ISO 9001
C. Windows API
D. POSIX / Single UNIX Specification