{"id":27607935,"url":"https://github.com/mevdschee/pidfile","last_synced_at":"2025-07-10T07:04:06.976Z","repository":{"id":274870711,"uuid":"924337708","full_name":"mevdschee/pidfile","owner":"mevdschee","description":"A Go package for single-instance execution using a PID file","archived":false,"fork":false,"pushed_at":"2025-03-19T01:40:31.000Z","size":18,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-22T22:18:29.196Z","etag":null,"topics":["go","golang","golang-package"],"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/mevdschee.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":"2025-01-29T20:27:25.000Z","updated_at":"2025-03-19T01:32:32.000Z","dependencies_parsed_at":"2025-04-22T22:28:36.029Z","dependency_job_id":null,"html_url":"https://github.com/mevdschee/pidfile","commit_stats":null,"previous_names":["mevdschee/pidfile"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/mevdschee/pidfile","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mevdschee%2Fpidfile","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mevdschee%2Fpidfile/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mevdschee%2Fpidfile/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mevdschee%2Fpidfile/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mevdschee","download_url":"https://codeload.github.com/mevdschee/pidfile/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mevdschee%2Fpidfile/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264545014,"owners_count":23625387,"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","golang-package"],"created_at":"2025-04-22T22:18:19.833Z","updated_at":"2025-07-10T07:04:06.947Z","avatar_url":"https://github.com/mevdschee.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pidfile package for Go\n\nThe `pidfile` package provides a simple way to ensure that only one instance of a Go application runs at any given time by using a file that contains a decimal number also known as the PID (short for process identifier).\n\n## Features\n\n- Detects that the an instance of the application is already running.\n- Allows you to prevents multiple instances of the application from running concurrently.\n- Signals the first instance of the application when a next instance is started.\n- Passes the command line arguments of any next instance to the first instance.\n\n## Installation\n\nTo install the `pidfile` package, use the following `go get` command:\n\n    go get github.com/mevdschee/pidfile\n\n## Example\n\nHere is an example of an application that uses the pidfile package to ensure single instance execution:\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\n\t\"github.com/mevdschee/pidfile\"\n)\n\nfunc main() {\n\n\t// create pidfile struct based on identifier\n\tpf := pidfile.New(\"app_identifier\")\n\t// when a second instance is started\n\tpf.OnSecond = func(args []string) {\n\t\tlog.Printf(\"another instance was started\")\n\t}\n\t// create pidfile on application start\n\terr := pf.Create()\n\tif err != nil {\n\t\tlog.Fatalf(\"can't create pidfile: %v\", err)\n\t}\n\t// remove pidfile on application close\n\tdefer pf.Remove()\n\t// if this is not the first instance, then close it\n\tif pf.FirstPid != os.Getpid() {\n\t\treturn\n\t}\n\n\t// application code\n}\n\n```\n\nNB: This package was built for usage in a (desktop) [Fyne](https://fyne.io/) project.\n\n## Future work / Known issues\n\nThe following issues need addressing in future versions:\n\n- Add parallel tests to validate starting once does not have race conditions\n- Add parallel tests to validate arguments lock prevents race conditions\n\n## Credits / related work\n\nThe following packages have inspired me to make this package:\n\n- https://github.com/postfinance/single\n- https://github.com/makifdb/pidfile\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmevdschee%2Fpidfile","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmevdschee%2Fpidfile","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmevdschee%2Fpidfile/lists"}