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

2 When 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

3 Which 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)

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. 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

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. 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. 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[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]

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

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

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

11 Unlike 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

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

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

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

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 blocks until a process opens the FIFO for writing
D. It returns a random file descriptor

15 How 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

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

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

17 How 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()

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

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

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

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

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

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

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

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

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

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

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

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

26 Does 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

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

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

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

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

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

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

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

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

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

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

A. ipcrm
B. delshm
C. rm
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 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

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

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

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. 0xDEADBEEF
B. NULL
C. Undefined
D. (void *) -1

37 In 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()

38 When 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

39 A FIFO is also known as:

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

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

A. <unistd.h>
B. <sys/shm.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 child inherits the shared memory ID (shmid)
B. The fork fails
C. The segment is deleted
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 OS kills the child
C. The child inherits the attached shared memory segment
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. EINVAL
B. ENOMEM
C. EEXIST
D. EACCES

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

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. Networking protocols
C. Synchronization (e.g., Semaphores)
D. More shared memory

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

48 The 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

49 When 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

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

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