Unit 6 - Practice Quiz

CSE325

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

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

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

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

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

5 Which system call is used to create a Named Pipe (FIFO)?

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

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

7 When using Shared Memory, which IPC mechanism is typically defined as the fastest?

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

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

9 What is the return value of the pipe() system call upon failure?

A.
B. 1
C. -1
D. NULL

10 Which command line utility allows you to create a named pipe?

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

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

12 Which file type character represents a named pipe in the output of ls -l?

A. -
B. d
C. l
D. p

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

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

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

16 Which header file is required for the pipe() system call?

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

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

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

19 In POSIX Shared Memory, which function creates or opens a shared memory object?

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

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

21 Which command allows a user to remove a shared memory segment from the command line?

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

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

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

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

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

26 Which function maps a POSIX shared memory object into the process's address space?

A. shm_attach()
B. shmat()
C. mmap()
D. map_shared()

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

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

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

30 Which function closes the stream opened by popen()?

A. close()
B. fclose()
C. pclose()
D. end()

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

32 Which command displays information about active Shared Memory segments?

A. ls
B. ps -ef
C. ipcs -m
D. netstat

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

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

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

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

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

38 Which of the following is NOT a valid argument for the shmflg parameter in shmat()?

A. SHM_RDONLY
B. SHM_RND
C.
D. O_CREAT

39 Data written to a pipe is treated as:

A. A stream of bytes.
B. Structured records.
C. Linked lists.
D. Indexed blocks.

40 To 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()

41 What is the return type of shmat()?

A. int
B. void *
C. char *
D. struct shmid_ds

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

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

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

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

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

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

48 What is the typical default capacity of a pipe on modern Linux systems?

A. 512 bytes
B. 4 KB
C. 64 KB
D. 1 MB

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

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