click below
click below
Normal Size Small Size show me how
CECS326 Dungeon
| Question | Answer |
|---|---|
| What is the correct order for creating shared memory for the first time? | shm_open → ftruncate → mmap |
| Why is ftruncate() typically called when creating shared memory? | To resize the shared memory region to the desired number of bytes |
| What does mmap() return? | A pointer to the mapped memory region |
| After a successful mmap() call, how is the returned value commonly used? | As a pointer to access shared memory like normal memory |
| What does fork() return to the parent process? | The child process ID |
| What does fork() return to the child process? | 0 |
| Why is the return value of fork() useful? | It allows the process to determine whether it is the parent or child |
| If exec() works successfully, what happens to the original program? | It is replaced entirely by the new program image |
| Which shared memory functions are typically needed in processes after the first creator process? | shm_open() and mmap() |
| Why is ftruncate() usually unnecessary in later processes using existing shared memory? | The shared memory size has already been established |
| How are structs typically stored in memory? | As contiguous fields in a single block of memory |
| If a struct is stored in shared memory, how are its fields accessed? | Using normal struct field access through pointers |
| Which operator is commonly used to access fields through a pointer to a struct? | -> |
| How can you determine the size of a struct in bytes in C/C++? | sizeof(struct_name) |
| Explain the general steps required to create shared memory for the first time. | a process usually calls shm_open() to create or open the shared memory object. ftruncate() is used to set the size of the shared memory region. mmap() maps that shared memory into the process’s address space so it can be accessed like normal memory. |
| What does fork() return, and how is that information typically used in a program? | fork() returns twice because it creates a new child process. In the parent process, it returns the child’s PID, while in the child process it returns 0. The program determines which code should run in the parent and which in the child after fork occurs. |
| What happens if exec() executes successfully? | If exec() succeeds, the current process is completely replaced by the new program image. The original code, variables, and instructions are overwritten, and execution continues as the new program instead of returning to the old one. |
| Describe how a struct is stored in memory and how its fields are accessed if the struct is placed in shared memory. | struct is stored as a contiguous block of memory containing all of its fields in order. If struct is placed in shared memory, can be accessed using a pointer like a normal struct. The fields are typically accessed using the -> operator for pointers. |