Unit 6 - Practice Quiz

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

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

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

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

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

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

A. Only between a process and the kernel
B. Processes that have a parent-child or common ancestor relationship
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 fails with an error immediately
B. The write() call blocks until sufficient space is available
C. The data is discarded
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. SIGKILL
B. SIGPIPE
C. SIGINT
D. SIGSEGV

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. EOF
B. 1
C. 0
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 fd[0] and write to fd[1]
B. Close both and use shared memory
C. Keep both open 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. exec()
B. popen()
C. mkfifo()
D. system()

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

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

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

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

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

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

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

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

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. Use the O_NONBLOCK flag in open()
C. It is not possible
D. Use open_async()

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

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

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

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

18 Is 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, but only if the buffer overflows
C. Yes, it acts exactly like a text file
D. No, it is stored in the CPU registers

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

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

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

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

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

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

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

A. The size of the memory created
B. Zero
C. A non-negative integer (Shmid)
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. 0
B. The shmid
C. A pointer (void *) to the attached memory segment
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. shmdt()
D. delete()

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

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

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_STAT
B. IPC_RMID
C. IPC_SET
D. SHM_DEL

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

A. Race conditions (read/write conflicts)
B. Packet loss
C. Deadlock only
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_NOWAIT
B. IPC_EXCL
C. O_TRUNC
D. IPC_FORCE

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

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

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

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

33 In 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 permanently on the hard drive
C. Memory is cleared every time a context switch occurs
D. Memory persists only while the creating process is alive

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

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

35 Which 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()

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

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

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

A. fopen()
B. shm_open()
C. shmget()
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. Message Queue
B. Unnamed Pipe
C. Named Pipe
D. Socket Pair

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

A. <sys/shm.h>
B. <unistd.h>
C. <sys/socket.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 child inherits the shared memory ID (shmid)
C. The child automatically attaches to it
D. The fork fails

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 child must re-attach manually
D. The OS kills the child

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

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

44 What is the relationship between mmap and shared memory?

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

45 Why might mkfifo() fail with EEXIST?

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

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

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

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

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

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

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

49 When data is read from a pipe:

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

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

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