{"id":26826735,"url":"https://github.com/hslam/ipc","last_synced_at":"2025-04-28T17:01:37.136Z","repository":{"id":144227425,"uuid":"316816884","full_name":"hslam/ipc","owner":"hslam","description":"Package ipc provides a way to use System V IPC, including message queues, semaphore, and shared memory.","archived":false,"fork":false,"pushed_at":"2021-01-16T19:10:36.000Z","size":22,"stargazers_count":7,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T11:32:46.696Z","etag":null,"topics":["go","golang","ipc","message-queues","msg","msgget","sem","semaphore","semget","shared-memory","shm","shmget","system-v","unix"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hslam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-11-28T20:31:55.000Z","updated_at":"2024-09-13T08:58:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"2e292057-570d-4cf6-871f-6ac4f319891c","html_url":"https://github.com/hslam/ipc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fipc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fipc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fipc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hslam%2Fipc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hslam","download_url":"https://codeload.github.com/hslam/ipc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251352245,"owners_count":21575858,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","ipc","message-queues","msg","msgget","sem","semaphore","semget","shared-memory","shm","shmget","system-v","unix"],"created_at":"2025-03-30T11:30:49.994Z","updated_at":"2025-04-28T17:01:37.090Z","avatar_url":"https://github.com/hslam.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ipc\n[![PkgGoDev](https://pkg.go.dev/badge/github.com/hslam/ipc)](https://pkg.go.dev/github.com/hslam/ipc)\n[![Build Status](https://github.com/hslam/ipc/workflows/build/badge.svg)](https://github.com/hslam/ipc/actions)\n[![codecov](https://codecov.io/gh/hslam/ipc/branch/master/graph/badge.svg)](https://codecov.io/gh/hslam/ipc)\n[![Go Report Card](https://goreportcard.com/badge/github.com/hslam/ipc)](https://goreportcard.com/report/github.com/hslam/ipc)\n[![LICENSE](https://img.shields.io/github/license/hslam/ipc.svg?style=flat-square)](https://github.com/hslam/ipc/blob/master/LICENSE)\n\nPackage ipc provides a way to use System V IPC. System V IPC includes three interprocess communication mechanisms that are widely available on UNIX systems: message queues, semaphore, and shared memory.\n\n## Features\n* [Ftok](https://github.com/hslam/ftok \"ftok\")\n* [Message queues](https://github.com/hslam/msg \"msg\")\n* [Semaphores](https://github.com/hslam/sem \"sem\")\n* [Shared memory](https://github.com/hslam/shm \"shm\")\n\n## Get started\n\n### Install\n```\ngo get github.com/hslam/ipc\n```\n### Import\n```\nimport \"github.com/hslam/ipc\"\n```\n### Usage\n####  Example\n```go\npackage main\n\nimport (\n\t\"encoding/binary\"\n\t\"flag\"\n\t\"fmt\"\n\t\"github.com/hslam/ipc\"\n\t\"os\"\n\t\"os/signal\"\n\t\"syscall\"\n)\n\nvar send = flag.Bool(\"s\", true, \"send\")\n\nfunc main() {\n\tflag.Parse()\n\tkey, _ := ipc.Ftok(\"/tmp\", 0x22)\n\tsemnum := 0\n\tsemid, err := ipc.Semget(key, 1, 0666)\n\tif err != nil {\n\t\tsemid, err = ipc.Semget(key, 1, ipc.IPC_CREAT|ipc.IPC_EXCL|0666)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t\t_, err := ipc.Semsetvalue(semid, semnum, 1)\n\t\tif err != nil {\n\t\t\tpanic(err)\n\t\t}\n\t}\n\tdefer ipc.Semrm(semid)\n\tshmid, data, _ := ipc.Shmgetattach(key, 128, ipc.IPC_CREAT|0600)\n\tdefer ipc.Shmrm(shmid)\n\tdefer ipc.Shmdetach(data)\n\tmsgid, _ := ipc.Msgget(key, ipc.IPC_CREAT|0600)\n\tdefer ipc.Msgrm(msgid)\n\tvar text string\n\tquit := make(chan os.Signal)\n\tsignal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)\n\tgo func() {\n\t\tdefer close(quit)\n\t\tif *send {\n\t\t\tfmt.Println(\"Enter:\")\n\t\t\tbuf := make([]byte, 10)\n\t\t\tfor {\n\t\t\t\tfmt.Scanln(\u0026text)\n\t\t\t\tif _, err := ipc.Semp(semid, semnum, ipc.SEM_UNDO); err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tcopy(data, text)\n\t\t\t\tif _, err := ipc.Semv(semid, semnum, ipc.SEM_UNDO); err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tn := binary.PutUvarint(buf, uint64(len(text)))\n\t\t\t\tif err := ipc.Msgsend(msgid, 1, buf[:n], 0600); err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tfmt.Println(\"Recv:\")\n\t\t\tfor {\n\t\t\t\tm, err := ipc.Msgreceive(msgid, 1, 0600)\n\t\t\t\tif err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tlength, _ := binary.Uvarint(m)\n\t\t\t\tif _, err := ipc.Semp(semid, semnum, ipc.SEM_UNDO); err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\ttext = string(data[:length])\n\t\t\t\tif _, err := ipc.Semv(semid, semnum, ipc.SEM_UNDO); err != nil {\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t\tfmt.Println(text)\n\t\t\t}\n\t\t}\n\t}()\n\t\u003c-quit\n}\n```\n\n#### Output\nEnter a word.\n```sh\n$ go run main.go -s=true\nEnter:\nHelloWorld\n```\nIn another terminal receive this word.\n```sh\n$ go run main.go -s=false\nRecv:\nHelloWorld\n```\n\n### License\nThis package is licensed under a MIT license (Copyright (c) 2020 Meng Huang)\n\n\n### Author\nipc was written by Meng Huang.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Fipc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhslam%2Fipc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhslam%2Fipc/lists"}