Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C program to create a mmap() that is shared by multiple threads. Use fst

ID: 3856722 • Letter: W

Question

Write a C program to create a mmap() that is shared by multiple threads. Use fstat() to obtain the size of the mapped file to size the mapping. Find out the number of logical processors (or cores) available programmatically by calling sysconf(), as shown, and display this number.

int numCPU = sysconf(_SC_NPROCESSORS_ONLN);

For this problem, however, you are going to create four (4) threads only. Every     thread should see the mapping. Each thread will display separate partial contents (sb.st_size/4 bytes) of the file.

Finally, unmap and close the file.

Please show the command line and the screenshots

Explanation / Answer

#ifdef _WIN32 #include #elif MACOS #include #include #else #include #endif int getNumCores() { #ifdef WIN32 SYSTEM_INFO sysinfo; GetSystemInfo(&sysinfo); return sysinfo.dwNumberOfProcessors; #elif MACOS int nm[2]; size_t len = 4; uint32_t count; nm[0] = CTL_HW; nm[1] = HW_AVAILCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) { nm[1] = HW_NCPU; sysctl(nm, 2, &count, &len, NULL, 0); if(count < 1) { count = 1; } } return count; #else return sysconf(_SC_NPROCESSORS_ONLN); #endif }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote