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. mkfifo()
C. open()
D. shmget()

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. Circular
B. Bidirectional (Full Duplex)
C. Unidirectional (Half Duplex)
D. Random Access

4 Unnamed 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. Only between a process and the kernel
C. Any two processes on the network
D. Any two processes on the same system, even if unrelated

5 What 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

6 Which signal is generated if a process attempts to write to a pipe for which the read end has been closed?

A. SIGKILL
B. SIGSEGV
C. SIGPIPE
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. EOF
C. 1
D. -1

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. Keep both open and write to fd[1]
C. Close fd[0] and write to fd[1]
D. Close fd[1] and write to fd[0]

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A. Using shmdt()
B. Using close()
C. It is automatically removed when processes exit
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. No, it is stored in the CPU registers
C. Yes, but only if the buffer overflows
D. No, the data is held in kernel buffers and passes to the reader

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

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

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. ftok()
B. rand()
C. time()
D. getpid()

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

A. A non-negative integer (Shmid)
B. Zero
C. The size of the memory created
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. shmat()
B. mmap()
C. shmdt()
D. shmget()

24 What does shmat() return on success?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 allow the writer to write faster
C. To save memory
D. To prevent the reader from hanging waiting for EOF

39 A FIFO is also known as:

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

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

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

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

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

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

A. The child inherits the attached shared memory segment
B. The OS kills the child
C. The memory becomes private to the parent
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. EEXIST
B. EACCES
C. EINVAL
D. ENOMEM

44 What is the relationship between mmap and shared memory?

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

45 Why might mkfifo() fail with EEXIST?

A. The process has no permission
B. The disk is full
C. The pathname already exists
D. The system limit for pipes is reached

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

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

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

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

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

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

49 When data is read from a pipe:

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

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

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