> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ns.rocks/llms.txt
> Use this file to discover all available pages before exploring further.

# Processes

> List processes, send stdin, inspect logs, and kill work by PID.

## List running processes

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
for process in machine.commands.list():
    state = "running" if process.running else "exited"
    print(process.pid, state, process.command)
```

`ProcessInfo` includes `pid`, `command`, and `running`. The list endpoint is
useful for reconnecting to background work after a client restart.

## Send stdin

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
process = machine.commands.run("python3 -i", shell=True, background=True)
machine.commands.send_stdin(process.pid, "print('hello')\n")
machine.commands.send_stdin(process.pid, "exit()\n")
```

`send_stdin` writes text to the process stdin stream. Use it for interactive
programs that are not full terminal sessions; use [PTY sessions](../access/pty)
when terminal behavior, resize, or shell line editing matters.

## Logs

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
logs = machine.commands.get_logs(process.pid)
print(logs.stdout)
print(logs.stderr)
print(logs.output)
print(logs.exit_code)
```

`stdout` and `stderr` are split streams. `output` is the interleaved stream when
the backend has it. `exit_code` is `None` while the process is still running and
an integer after it exits.

## Kill

```python theme={"theme":{"light":"one-light","dark":"one-dark-pro"}}
machine.commands.kill(process.pid)
```

Killing a process does not destroy the machine. It only stops the selected PID.

## REST and CLI map

| Task           | Python SDK                               | CLI                                                          | API                                            |
| -------------- | ---------------------------------------- | ------------------------------------------------------------ | ---------------------------------------------- |
| List processes | `machine.commands.list()`                | `nullspace machine process list mch_123`                     | `GET /v1/machines/{id}/processes`              |
| Fetch logs     | `machine.commands.get_logs(pid)`         | `nullspace machine process logs mch_123 1234`                | `GET /v1/machines/{id}/processes/{pid}/logs`   |
| Send stdin     | `machine.commands.send_stdin(pid, data)` | `printf ... \| nullspace machine process stdin mch_123 1234` | `POST /v1/machines/{id}/processes/{pid}/stdin` |
| Kill           | `machine.commands.kill(pid)`             | `nullspace machine process kill mch_123 1234`                | `POST /v1/machines/{id}/processes/{pid}/kill`  |
| Attach stream  | `machine.commands.connect(pid)`          | `nullspace machine process attach mch_123 1234`              | exec WebSocket                                 |

Most CLI process commands accept `--json` for automation. `stdin --json`
returns the PID and `bytes_sent`; `attach --json` returns a `CommandResult`.

## Related

* [Commands](./overview)
* [Streaming output](./streaming)
* [Monitor stream](../observability/monitor)
