gitee.com/sy_183/go-common@v1.0.5-0.20231205030221-958cfe129b47/ipc/cgo/shm/test/write/main.go (about) 1 package main 2 3 import ( 4 shmPkg "gitee.com/sy_183/go-common/ipc/cgo/shm" 5 "os" 6 "syscall" 7 "time" 8 ) 9 10 func main() { 11 const l = 4096 12 shm, err := shmPkg.Open("test", os.O_CREATE|os.O_RDWR, 0644) 13 if err != nil { 14 panic(err) 15 } 16 defer shm.Close() 17 if err = shm.Truncate(l); err != nil { 18 panic(err) 19 } 20 if err = shm.Mmap(0, l, syscall.PROT_READ|syscall.PROT_WRITE, syscall.MAP_SHARED); err != nil { 21 panic(err) 22 } 23 shm.Data()[copy(shm.Data(), time.Now().Format(time.RFC3339Nano))] = 0 24 }