Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/shmPublic

Package shm provides a way to use System V shared memory.

License

NotificationsYou must be signed in to change notification settings

hslam/shm

Repository files navigation

PkgGoDevBuild StatusGo Report CardLICENSE

Package shm provides a way to use System V shared memory.

Get started

Install

go get github.com/hslam/shm

Import

import "github.com/hslam/shm"

Usage

SHM GET Example

Writer

package mainimport ("fmt""github.com/hslam/ftok""github.com/hslam/shm""time")funcmain() {key,err:=ftok.Ftok("/tmp",0x22)iferr!=nil {panic(err)}shmid,data,err:=shm.GetAttach(key,128,shm.IPC_CREAT|0600)iferr!=nil {panic(err)}defershm.Remove(shmid)defershm.Detach(data)context:= []byte("Hello World")copy(data,context)fmt.Println(string(data[:11]))time.Sleep(time.Second*10)}

Reader

package mainimport ("fmt""github.com/hslam/ftok""github.com/hslam/shm")funcmain() {key,err:=ftok.Ftok("/tmp",0x22)iferr!=nil {panic(err)}_,data,err:=shm.GetAttach(key,128,0600)iferr!=nil {panic(err)}defershm.Detach(data)fmt.Println(string(data[:11]))}

Output

Hello World

SHM OPEN Example

Writer

package mainimport ("fmt""github.com/hslam/mmap""github.com/hslam/shm""time")funcmain() {name:="shared"fd,err:=shm.Open(name,shm.O_RDWR|shm.O_CREATE,0600)iferr!=nil {panic(err)}defershm.Unlink(name)defershm.Close(fd)length:=128shm.Ftruncate(fd,int64(length))data,err:=mmap.Open(fd,0,length,mmap.READ|mmap.WRITE)iferr!=nil {panic(err)}defermmap.Munmap(data)context:= []byte("Hello World")copy(data,context)fmt.Println(string(data[:11]))time.Sleep(time.Second*10)}

Reader

package mainimport ("fmt""github.com/hslam/mmap""github.com/hslam/shm")funcmain() {name:="shared"fd,err:=shm.Open(name,shm.O_RDONLY,0600)iferr!=nil {panic(err)}defershm.Close(fd)data,err:=mmap.Open(fd,0,128,mmap.READ)iferr!=nil {panic(err)}defermmap.Munmap(data)fmt.Println(string(data[:11]))}

Output

Hello World

License

This package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)

Author

shm was written by Meng Huang.

About

Package shm provides a way to use System V shared memory.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp