Lab 7 PDF
Lab 7 PDF
Lab 7 PDF
Return Values:
Upon successful completion, shmget() returns the positive integer identifier of a shared
memory segment. Otherwise, -1 is returned
Return Values:
Upon success, shmat() returns the address where the segment is attached; otherwise, -1 is
returned and errno is set to indicate the error.
This system call is used to detach a shared memory region from the process’s address space.
Return Values:
Upon success, shmdt() returns 0; otherwise, -1 is returned and errno is set to indicate the error.
How to Delete Shared Memory Region:
IPC_RMID marks the segment to be destroyed. The segment will actually be destroyed only
after the last process detaches it (The caller must be the owner or creator of the segment, or be
privileged). The buf argument is ignored.
Return Values:
For IPC_RMID operation, 0 is returned on success; else -1 is returned.
Shmctl(shmid, IPC_RMID, NULL);
In-Lab Questions:
1. Create a private shared memory in C/C++. The process then creates a child and
waits for the child to write the file’s contents to shared memory. The parent then
reads the shared memory and changes the case of each character and removes all
integers from the data. The child reads it back and writes the changed data back to
the same file. (The file name is passed as command line argument).
2. Create a C++/C program that creates a shared memory and waits for the other
process to write n data of n number of Students. The process that created the
shared memory then writes the data of students to the file.