devela::_dep::nc::call

Function shmat

pub unsafe fn shmat(
    shmid: i32,
    shm_addr: Option<*const c_void>,
    shm_flag: i32,
) -> Result<*const c_void, i32> 
Available on crate feature dep_nc only.
Expand description

Attach the System V shared memory segment.

§Examples

let size = 4 * nc::PAGE_SIZE;
let flags = nc::IPC_CREAT | nc::IPC_EXCL | 0o600;
let ret = unsafe { nc::shmget(nc::IPC_PRIVATE, size, flags) };
assert!(ret.is_ok());
let shmid = ret.unwrap();

let ret = unsafe { nc::shmat(shmid, None, 0) };
assert!(ret.is_ok());
let addr: *const std::ffi::c_void = ret.unwrap();

let mut buf = nc::shmid_ds_t::default();
let ret = unsafe { nc::shmctl(shmid, nc::IPC_STAT, &mut buf) };
assert!(ret.is_ok());

let ret = unsafe { nc::shmdt(addr) };
assert!(ret.is_ok());

let ret = unsafe { nc::shmctl(shmid, nc::IPC_RMID, &mut buf) };
assert!(ret.is_ok());