An open API service indexing awesome lists of open source software.

https://github.com/brandonkramer/procenv

Read one environment variable from another process by PID (Linux /proc, macOS ps). Stdlib-only Go library.
https://github.com/brandonkramer/procenv

environment go golang library linux process procfs

Last synced: 25 days ago
JSON representation

Read one environment variable from another process by PID (Linux /proc, macOS ps). Stdlib-only Go library.

Awesome Lists containing this project

README

          

# procenv

Read one environment variable from another process by pid.

## Install

From [pkg.go.dev](https://pkg.go.dev/github.com/brandonkramer/procenv):

```bash
go get github.com/brandonkramer/procenv@v0.1.0
```

## Usage

```go
value, ok := procenv.ProcEnv(pid, "MYAPP_RUN_ID")
if !ok {
// pid invalid, process gone, or key missing
}
```

| Platform | Mechanism |
|----------|-----------|
| Linux | `/proc//environ` |
| macOS | `ps eww -p ` |
| Other | always `("", false)` |

Invalid `pid` (≤ 0) or empty `key` returns `("", false)` without syscalls.

## Development

Lefthook and golangci-lint are pinned in `go.mod` as **tools** (dev-only). Install git hooks once per clone:

```bash
make install-hooks
```

```bash
make check
make test
make lint
```