...
1
2
3
4
5
6
7 package unix_test
8
9 import (
10 "log"
11
12 "golang.org/x/sys/unix"
13 )
14
15 func ExampleSysvShmGet() {
16
17 id, err := unix.SysvShmGet(unix.IPC_PRIVATE, 1024, unix.IPC_CREAT|unix.IPC_EXCL|0o600)
18 if err != nil {
19 log.Fatal("sysv shm create failed:", err)
20 }
21
22
23
24
25 defer func() {
26 _, err := unix.SysvShmCtl(id, unix.IPC_RMID, nil)
27 if err != nil {
28 log.Fatal(err)
29 }
30 }()
31
32
33 b, err := unix.SysvShmAttach(id, 0, 0)
34 if err != nil {
35 log.Fatal("sysv attach failed:", err)
36 }
37
38
39
40 defer func() {
41 if err = unix.SysvShmDetach(b); err != nil {
42 log.Fatal("sysv detach failed:", err)
43 }
44 }()
45
46
47
48 b[42] = 'h'
49 b[43] = 'i'
50 }
51
View as plain text