Determining the Page Size

Memory functions performed by the UNIX kernel are restricted to operating in multiples of the virtual memory (VM) page size. You have already seen this behavior when attaching shared memory. A portable program needs a way to determine what the system's VM page size is, because it varies on different UNIX platforms. The getpagesize(3) function returns this information. The function synopsis for it is as follows:

#include <unistd.h>

int getpagesize(void);

The function getpagesize(3) returns the size in bytes of the system page size used.

Note

The page size returned by getpagesize(3) is the size of the system's page size. The page size used by the hardware for virtual memory paging may be different in size.

Listing 26.1 ...

Get Advanced UNIX Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.