{"id":13788505,"url":"https://github.com/msantos/prx","last_synced_at":"2025-04-28T17:42:10.668Z","repository":{"id":43675866,"uuid":"43636593","full_name":"msantos/prx","owner":"msantos","description":"an Erlang library for interacting with Unix processes","archived":false,"fork":false,"pushed_at":"2023-11-10T12:19:19.000Z","size":618,"stargazers_count":36,"open_issues_count":0,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-05-14T05:02:58.850Z","etag":null,"topics":["capsicum","exec","fork","linux-namespaces","pledge","prctl","procctl","seccomp","signal","supervisor","system-programming"],"latest_commit_sha":null,"homepage":null,"language":"Erlang","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/msantos.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}},"created_at":"2015-10-04T12:59:37.000Z","updated_at":"2024-05-01T08:33:39.000Z","dependencies_parsed_at":"2023-11-10T13:32:35.370Z","dependency_job_id":"e4b6d26d-b8f9-4045-a484-d49b193e48c8","html_url":"https://github.com/msantos/prx","commit_stats":{"total_commits":241,"total_committers":1,"mean_commits":241.0,"dds":0.0,"last_synced_commit":"e5cd7db8214306f68d3c9cbd0ba15442d893d726"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msantos%2Fprx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msantos%2Fprx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msantos%2Fprx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/msantos%2Fprx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/msantos","download_url":"https://codeload.github.com/msantos/prx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251357658,"owners_count":21576749,"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":["capsicum","exec","fork","linux-namespaces","pledge","prctl","procctl","seccomp","signal","supervisor","system-programming"],"created_at":"2024-08-03T21:00:48.419Z","updated_at":"2025-04-28T17:42:10.646Z","avatar_url":"https://github.com/msantos.png","language":"Erlang","funding_links":[],"categories":["Libraries"],"sub_categories":[],"readme":"# prx\n\n[![Package Version](https://img.shields.io/hexpm/v/prx)](https://hex.pm/packages/prx)\n[![Hex Docs](https://img.shields.io/badge/hex-docs)](https://hexdocs.pm/prx/)\n\nAn Erlang library for Unix process management and system programming\ntasks.\n\nprx provides:\n\n* a safe, beam-friendly interface to system calls and other POSIX operations\n\n* simple, reliable OS process management by mapping Erlang processes to\n  a hierarchy of system processes\n\n* an interface for privilege separation operations to restrict processes\n\n* operations to isolate processes like containers and jails\n\n## Build\n\n```\n$ rebar3 compile\n```\n\n## Quick Start\n\n`prx` has two basic operations: fork and exec.\n\n```\n% Spawn a new system process\n{ok, Task} = prx:fork(),\n\n% And a child of the process\n{ok, Child} = prx:fork(Task).\n```\n\nAfter fork()'ing, other calls can be made. For example:\n\n```\nUID = prx:getuid(Task),\nPID = prx:getpid(Child).\n```\n\nCalling exec() causes the process I/O to be treated as streams of data:\n\n```\nok = prx:execvp(Child, [\"/bin/cat\", \"-n\"]),\nprx:stdin(Child, \"test\\n\"),\nreceive\n    {stdout,Child,Stdout} -\u003e\n        Stdout\nend.\n```\n\n## Usage\n\n* fork and exec /bin/cat\n\n  ```\n    {ok, Task} = prx:fork(),\n    ok = prx:execvp(Task, [\"/bin/cat\", \"-n\"],\n    prx:stdin(Task, \"test\\n\"),\n    receive {stdout, Task, _} = Out -\u003e Out end.\n  ```\n\n* creating a pipeline of child processes\n\n  prx processes can fork child prx processes:\n\n```\nbeam\n  |-erl_child_setup\n  |   `-prx\n  |       `-prx\n```\n\nAfter calling exec, the process tree looks like:\n\n```\nbeam\n  |-erl_child_setup\n  |   `-prx\n  |       `-cat\n```\n\n```\n    {ok, Task} = prx:fork(),\n    {ok, Child} = prx:fork(Task),\n    OSPid = prx:getpid(Child),\n    ok = prx:execvp(Child, [\"/bin/cat\", \"-n\"],\n    prx:stdin(Child, \"test\\n\"),\n    receive {stdout, Child, _} = Out -\u003e Out end.\n```\n\n* running `cat` within a containerized namespace\n\n  ```\n    application:set_env(prx, options, [{exec, \"sudo -n\"}]),\n    {ok, Task} = prx:fork(),\n    {ok, Child} = prx:clone(Task, [clone_newnet, clone_newpid, clone_newipc,\n        clone_newuts, clone_newns]),\n    OSPid = prx:getpid(Child),\n    ok = prx:execvp(Child, [\"/bin/cat\", \"-n\"],\n    prx:stdin(Child, \"test\\n\"),\n    receive {stdout, Child, _} = Out -\u003e Out end.\n  ```\n\n## Documentation\n\nhttps://hexdocs.pm/prx/\n\nSee also: [alcove](https://hexdocs.pm/alcove/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsantos%2Fprx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmsantos%2Fprx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmsantos%2Fprx/lists"}