Complete the code to create a pipe for communication between processes.
int pipefd[2]; if (pipe([1]) == -1) { perror("pipe"); exit(EXIT_FAILURE); }
The pipe system call requires an array of two integers to hold the file descriptors for the read and write ends of the pipe. Here, pipefd is the correct array name.
Complete the code to write data to the write end of the pipe.
char buf[] = "Hello"; write([1], buf, sizeof(buf));
In a pipe, pipefd[1] is the write end. To send data, you write to this descriptor.
Fix the error in the shared memory segment creation code.
int shmid = shmget(key, [1], IPC_CREAT | 0666); if (shmid < 0) { perror("shmget"); exit(1); }
The size argument to shmget must be a positive integer specifying the number of bytes to allocate. 1024 bytes is a common size for a shared memory segment.
Fill both blanks to attach to a shared memory segment and write a value.
char *shm_ptr = (char *) shmat(shmid, [1], [2]); if (shm_ptr == (char *) -1) { perror("shmat"); exit(1); } *shm_ptr = 'A';
SHM_RDONLY when intending to write.IPC_CREAT to shmat, which is invalid.To attach to shared memory with default address and read-write access, pass NULL as the address and 0 as the flags.
Fill all three blanks to create a dictionary comprehension that maps process IDs to their shared memory keys if the key is positive.
shm_dict = { [1]: [2] for pid, key in processes.items() if key [3] 0 }This comprehension creates a dictionary where each process ID (pid) maps to its shared memory key (key) only if the key is greater than zero.