LU5 IPC Flashcards

1
Q

What does IPC stand for in system programming?

A

Interprocess Communication

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the primary purpose of IPC?

A

To allow two or more processes to exchange information with each other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Name two types of IPC mechanisms that only support local usage.

A

Signals & pipes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What happens if the buffer in a pipe is empty?

A

The reader process will be suspended.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What happens if the buffer in a pipe is full?

A

The writer process will be suspended.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the pipe ‘|’ symbol in Linux?

A

It tells the shell to create a pipe, connecting the output of one process to the input of another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between unnamed and named pipes?

A

Unnamed pipes:

  • are temporary and used by related processes

Named pipes (FIFOs):

  • are permanent and can be used by unrelated processes.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What system call is used to create an unnamed pipe?

A

pipe()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are the two file descriptors returned by the pipe() system call?

A
  • reading (p[0])
  • writing (p[1])
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What happens if a process tries to write to a full pipe?

A

The writer process will be suspended until there is space in the pipe.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What happens if a process tries to read from an empty pipe?

A

The reader process will be suspended until data is available in the pipe.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the default behavior of pipes regarding data flow?

A

Pipes treat data on a first-in-first-out (FIFO) basis.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the minimum size of an unnamed pipe in most systems?

A

512 bytes
(depends)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What system call is used to create a named pipe (FIFO)?

A

mkfifo() or mknod()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the advantage of using named pipes over unnamed pipes?

A

Named pipes can be used by unrelated processes and have a larger buffer capacity.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the purpose of the fcntl() function in non-blocking I/O?

A

To set the O_NONBLOCK flag, which prevents blocking when reading from or writing to a pipe.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What does the O_NONBLOCK flag do when set on a pipe?

A

It makes read and write operations non-blocking, returning immediately even if the pipe is empty or full.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is the purpose of the fstat() function in IPC?

A

To obtain file’s metadata when have an open file descriptor.

To get the number of characters in the pipe using the st_size member of the stat structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What is the main drawback of unnamed pipes?

A

They cannot be used by unrelated processes and are temporary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What is the typical buffer capacity of a named pipe (FIFO)?

A

Around 40K bytes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the purpose of the wait() system call in IPC?

A

To avoid zombie processes by waiting for child processes to terminate.

22
Q

What is the difference between a unidirectional and bidirectional pipe?

A

unidirectional pipe:

*allows data flow in one direction

bidirectional pipe:

*allows data flow in both directions.

23
Q

What is the purpose of the close() system call in IPC?

A

To close file descriptors associated with a pipe when they are no longer needed.

24
Q

What is the purpose of the fork() system call in IPC?

A

To create a child process that can communicate with the parent process using pipes

25
What is the purpose of the exec() system call in IPC?
To replace the current process image with a new process image, often used in conjunction with fork().
26
What is the purpose of the mknod command in UNIX?
To create special files, including named pipes (FIFOs).
27
What is the purpose of the mkfifo() system call?
To create a named pipe (FIFO) with a specified pathname and access permissions.
28
What is the purpose of the O_NONBLOCK flag in the open() system call?
To prevent blocking when opening a FIFO for reading or writing.
29
What is the purpose of the `perror()` function in IPC?
To print an error message to `stderr`(fd=2) based on the current value of `errno`.
30
What is the purpose of the exit() function in IPC?
To terminate a process and return a status code to the parent process.
31
What is the purpose of the `read()` system call in IPC?
To read data from a **pipe** or **file descriptor**.
32
What is the purpose of the write() system call in IPC?
To write data to a pipe or file descriptor.
33
how to check if a child is created successfully using fork()?
return 0
34
What is the purpose of the wait(NULL) system call in IPC examples?
To make the parent process wait for the child process to terminate.
35
What is the purpose of the close(p[0]) call in IPC examples?
To close the read end of the pipe in the child process.
36
What is the purpose of the close(p[1]) call in IPC examples?
To close the write end of the pipe in the parent process.
37
What is the purpose of the exit(1) call in IPC examples?
To terminate the process with a status code of 1 if an error occurs.
38
What is the purpose of the exit(0) call in IPC examples?
To terminate the process with a status code of 0, indicating success.
39
What is the purpose of the printf() function in IPC examples?
To print the contents of the buffer read from the pipe.
40
What is the purpose of the char inbuf[MSGSIZE] declaration in IPC examples?
To declare a buffer for storing data read from the pipe.
41
What is the purpose of the int p[2] declaration in IPC examples?
To declare an array to hold the file descriptors for the pipe.
42
What is the purpose of the pid_t pid declaration in IPC examples?
To declare a variable to hold the process ID returned by fork().
43
What is the purpose of the wait system call in IPC?
To make the parent process wait for the child process to terminate.
44
What is the purpose of the O_RDONLY flag in the open() system call?
To open a file or FIFO for reading only.
45
What is the purpose of the O_WRONLY flag in the open() system call?
To open a file or FIFO for writing only.
46
What is the purpose of the O_RDWR flag in the open() system call?
To open a file or FIFO for both reading and writing.
47
What is the purpose of the O_CREAT flag in the open() system call?
To create a file or FIFO if it does not already exist.
48
What is the purpose of the O_TRUNC flag in the open() system call?
To truncate a file to zero length if it already exists.
49
What is the purpose of the O_APPEND flag in the open() system call?
To append data to the end of a file instead of overwriting it.
50
What is the purpose of the O_EXCL flag in the open() system call?
To ensure that a file or FIFO is created exclusively, failing if it already exists.
51
What is the purpose of the O_NONBLOCK flag in the open() system call?
To make the open operation non-blocking, returning immediately even if the file or FIFO is not ready.