gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/ipc/cgo/shm/test/read/main.go (about) 1 package main 2 3 import ( 4 "bytes" 5 "fmt" 6 shmPkg "gitee.com/sy_183/go-common/ipc/cgo/shm" 7 "os" 8 "syscall" 9 ) 10 11 func main() { 12 const l = 4096 13 shm, err := shmPkg.Open("test", os.O_RDONLY, 0644) 14 if err != nil { 15 panic(err) 16 } 17 defer shm.Close() 18 if err = shm.Mmap(0, l, syscall.PROT_READ, syscall.MAP_SHARED); err != nil { 19 panic(err) 20 } 21 data := shm.Data() 22 if i := bytes.IndexByte(data, 0); i > 0 { 23 fmt.Println(string(data[:i])) 24 } 25 }