{"id":19846528,"url":"https://github.com/hekmon/processpriority","last_synced_at":"2025-02-28T20:18:55.086Z","repository":{"id":244805326,"uuid":"816285133","full_name":"hekmon/processpriority","owner":"hekmon","description":"Easily change a process priority from a Golang program","archived":false,"fork":false,"pushed_at":"2024-06-17T14:09:06.000Z","size":9,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-11T12:37:45.584Z","etag":null,"topics":["linux","nice","priority","process","windows"],"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/hekmon.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":"2024-06-17T12:33:05.000Z","updated_at":"2024-12-07T00:55:01.000Z","dependencies_parsed_at":"2024-06-17T15:42:40.840Z","dependency_job_id":"28c9c20d-a4ec-41dc-a955-d667b313ac28","html_url":"https://github.com/hekmon/processpriority","commit_stats":null,"previous_names":["hekmon/processpriority"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekmon%2Fprocesspriority","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekmon%2Fprocesspriority/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekmon%2Fprocesspriority/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hekmon%2Fprocesspriority/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hekmon","download_url":"https://codeload.github.com/hekmon/processpriority/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241225371,"owners_count":19930164,"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":["linux","nice","priority","process","windows"],"created_at":"2024-11-12T13:11:44.834Z","updated_at":"2025-02-28T20:18:55.055Z","avatar_url":"https://github.com/hekmon.png","language":"Go","readme":"# Process Priority\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/hekmon/processpriority.svg)](https://pkg.go.dev/github.com/hekmon/processpriority)\n\nEasily get or set a process priority from a Golang program with transparent Linux/Windows support.\n\nUnder the hood, it will uses pre-defined nice values for Linux and the priority classes for Windows.\n\n## Notes\n\n### Linux\n\nOn Linux, a user can only decrease its priority (increase its nice value), not increase it. This means that even after lowering the priority, you won't be able to raise it to its original value.\n\nTo be able to increase it, the user must be root or have the `CAP_SYS_NICE` capability.\n\n### Windows\n\nOn Windows, the real time priority can only be set as an administrator. If you try to set it as a normal user, you will won't get an error but your process will be set at `High` instead.\n\n## Example\n\n```golang\npackage main\n\nimport (\n\t\"fmt\"\n\t\"os/exec\"\n\n\t\"github.com/hekmon/processpriority\"\n)\n\nfunc main() {\n\t// Run command\n\t// cmd := exec.Command(\"sleep\", \"1\") // linux binary\n\tcmd := exec.Command(\"./sleep.exe\") // windows binary\n\terr := cmd.Start()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\t// Get its current priority\n\tprio, rawPrio, err := processpriority.Get(cmd.Process.Pid)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"Current process priority is %s (%d)\\n\", prio, rawPrio)\n\t// Change its priority\n\tnewPriority := processpriority.BelowNormal\n\tfmt.Printf(\"Changing process priority to %s\\n\", newPriority)\n\tif err = processpriority.Set(cmd.Process.Pid, newPriority); err != nil {\n\t\tpanic(err)\n\t}\n\t// Verifying\n\tif prio, rawPrio, err = processpriority.Get(cmd.Process.Pid); err != nil {\n\t\tpanic(err)\n\t}\n\tfmt.Printf(\"Current process priority is %s (%d)\\n\", prio, rawPrio)\n\t// Wait for the cmd to end\n\tif err = cmd.Wait(); err != nil {\n\t\tpanic(err)\n\t}\n}\n```\n\n### Linux output\n\n```\nCurrent process priority is Normal (0)\nChanging process priority to Below Normal\nCurrent process priority is Below Normal (5)\n```\n\n### Windows output\n\n```\nCurrent process priority is Normal (32)\nChanging process priority to Below Normal\nCurrent process priority is Below Normal (16384)\n```\n\n## Install\n\n```bash\ngo get -u github.com/hekmon/processpriority\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhekmon%2Fprocesspriority","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhekmon%2Fprocesspriority","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhekmon%2Fprocesspriority/lists"}