Check out example codes for "centos7 mlock2". It will help you in understanding the concepts better.

Code Example 1

#define _GNU_SOURCE
#include <unistd.h>
#include <errno.h>
#include <asm-generic/mman-common.h>
#include <sys/syscall.h>
#include <sys/mman.h>

inline int mlock2(const void* addr, size_t length, unsigned int flags) noexcept
{
    if (flags == 0)
    {
        return mlock(addr, length);
    }
    int ret = syscall(SYS_mlock2, addr, length, flags);
    return (ret == 0 || errno != ENOSYS) ? ret : -1;
}

Learn ReactJs, React Native from akashmittal.com