{"id":16918271,"url":"https://github.com/rustatian/ipc","last_synced_at":"2026-04-02T02:38:10.830Z","repository":{"id":57626409,"uuid":"294530901","full_name":"rustatian/IPC","owner":"rustatian","description":"Linux, Unix, and Windows implementation of SysV5 shared memory and semaphores.","archived":false,"fork":false,"pushed_at":"2025-04-07T09:23:32.000Z","size":195,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-11T16:32:41.918Z","etag":null,"topics":["interprocess","segment","semaphore","shared-memory-communication"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rustatian.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,"zenodo":null}},"created_at":"2020-09-10T21:54:44.000Z","updated_at":"2025-04-07T09:23:29.000Z","dependencies_parsed_at":"2024-08-14T12:56:23.352Z","dependency_job_id":"53cd55b4-793d-48d1-a6f5-d804913a8e20","html_url":"https://github.com/rustatian/IPC","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustatian%2FIPC","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustatian%2FIPC/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustatian%2FIPC/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rustatian%2FIPC/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rustatian","download_url":"https://codeload.github.com/rustatian/IPC/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248441370,"owners_count":21103981,"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":["interprocess","segment","semaphore","shared-memory-communication"],"created_at":"2024-10-13T19:39:26.702Z","updated_at":"2026-04-02T02:38:10.802Z","avatar_url":"https://github.com/rustatian.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Linux and Windows implementation of shared memory and semaphores\r\n\r\n\u003cp align=\"center\"\u003e\r\n\t\u003ca href=\"https://github.com/rustatian/IPC/actions\"\u003e\u003cimg src=\"https://github.com/rustatian/IPC/workflows/CI/badge.svg\" alt=\"\"\u003e\u003c/a\u003e\r\n\u003c/p\u003e\r\n\r\n# How to use\r\n## Semaphores (interprocess):\r\n\r\nProcess1: Initialize a semaphore, and Add to semaphores set (semaphore 0 in example) value 1. And start doing some interprocess work (write to the shared memory for example).\r\n```go\r\ns, err := NewSemaphore(0x12334, 1, 0666, true, IPC_CREAT)\r\nif err != nil {\r\n\tpanic(err)\r\n}\r\nerr = s.Add(0)\r\nif err != nil {\r\n\tpanic(err)\r\n}\r\n  ```\r\n  \r\n  After work will be done, just unlock semaphore:\r\n  \r\n  ```go\r\n  err = s.Done(0) // 0 here is the 1-st semaphore in the set identified by semaphore ID.\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n  ```\r\n  \r\n  Process2: Attach to the same semaphore. And `Wait` until Process1 released semaphore.\r\n  ```go\r\n\ts, err := NewSemaphore(0x12334, 1, 0666, false, IPC_CREAT)\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\terr = s.Wait()\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n  ```\r\n\r\n## Shared Memory (interprocess):\r\n\r\nInitialize shared memory segment with a key, required size and flags:\r\n```go\r\nseg1, err := NewSharedMemorySegment(0x1, 1024, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP, IPC_CREAT)\r\nif err != nil {\r\n\tt.Fatal(err)\r\n}\r\n```  \r\n\r\nWrite the specified amount of data and detach from the segment:\r\n```go\r\n// write data to the shared memory\r\n// testData is less or equal to 1024 specified in prev declaration \r\nseg1.Write([]byte(testData))\r\nerr = seg1.Detach()\r\nif err != nil {\r\n\tt.Fatal(err)\r\n}\r\n```\r\n\r\nFrom the another process, initialize shared memory segment with the same key, size, but with ReadOnly flag:\r\n\r\n```go\r\nseg2, err := NewSharedMemorySegment(0x1, 1024, 0, SHM_RDONLY)\r\nif err != nil {\r\n\tt.Fatal(err)\r\n}\r\n```\r\n\r\nRead specified amount of data and detach from the segment:\r\n\r\n```go\r\nbuf := make([]byte, len(testData), len(testData))\r\nerr = seg2.Read(buf)\r\nif err != nil {\r\n\tt.Fatal(err)\r\n}\r\nerr = seg2.Detach()\r\nif err != nil {\r\n\tt.Fatal(err)\r\n}\r\n\r\n```\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustatian%2Fipc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frustatian%2Fipc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frustatian%2Fipc/lists"}