Skip to content

Instantly share code, notes, and snippets.

@caelifer caelifer/page_size.go
Last active Oct 27, 2016

What would you like to do?
Getting page size on POSIX system.
// +build !windows
package main
import (
#include <errno.h>
#include <string.h>
#include <unistd.h>
int getErrno(void) {
return errno;
import "C"
func main() {
sz, err := getPageSize()
if err != nil {
fmt.Printf("Page size: %d\n", sz)
func getPageSize() (int, error) {
sz := int(C.sysconf(C._SC_PAGESIZE))
errno := C.getErrno()
if errno == C.EINVAL {
return -1, fmt.Errorf("C.sysconf: %s", C.GoString(C.strerror(errno)))
return sz, nil

This comment has been minimized.

Copy link
Owner Author

caelifer commented Oct 27, 2016

This program does not work on Windows. On RHEL 6 Linux and macOS Sierra it outputs:

$ go run page_size.go
Page size: 4096
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.