gopkg.in/ro-ag/posix.v1@v1.0.6/test/shm_exe.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "gopkg.in/ro-ag/posix.v1" 6 "log" 7 "os" 8 "unsafe" 9 ) 10 11 const ShmFile uintptr = 3 12 13 func main() { 14 fmt.Println("»»» run from extern program") 15 f := os.NewFile(ShmFile, "external memory") 16 bts, addr, err := posix.Mmap(nil, posix.Getpagesize(), posix.PROT_WRITE|posix.PROT_WRITE, posix.MAP_SHARED, int(f.Fd()), 0) 17 if err != nil { 18 log.Fatal("Mmap:", err) 19 } 20 fmt.Println("»»» got address", unsafe.Pointer(addr)) 21 textToWrite := fmt.Sprintf("PID: %.10d", os.Getpid()) 22 copy(bts, textToWrite) 23 if err = posix.Munmap(bts); err != nil { 24 log.Fatal(err) 25 } 26 }