Flatpak is a powerful software utility for software deployment, application virtualization, and package management. It enables developers to create and distribute applications that can run on different Linux distributions seamlessly. In this blog post, we’ll explore two important Flatpak commands: flatpak ps
and flatpak enter
.
Flatpak ps: Understanding Running Instances
The flatpak ps
command provides valuable insights into the currently running Flatpak instances on your system. Let’s break down what this command displays:
flatpak ps
Output Example:
Instance PID Application Runtime Version
1 123 org.example.App org.freedesktop.Platform 20.08
2 456 com.another.app org.kde.Platform 21.04
- Instance: A unique identifier for each running Flatpak instance.
- PID: Process ID associated with the instance.
- Application: The Flatpak application’s ID.
- Runtime: The runtime on which the Flatpak application depends.
- Version: The version of the runtime.
This information helps you monitor and manage the Flatpak instances running on your system.
Flatpak Enter: Interacting with a Specific Instance
While monitoring instances is useful, sometimes you need to interact with a specific Flatpak application’s environment. The flatpak enter
command facilitates this interaction. Let’s see how it works:
flatpak enter 1 ps aux
In this example, we enter the namespace of the Flatpak instance with the ID 1
and execute the ps aux
command within that environment.
Output Example:
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
user 1234 0.1 0.5 123456 78900 ? S Jan01 0:05 ps aux
user 5678 0.0 0.2 12345 6789 ? S Jan01 0:02 /bin/sh
- USER: The owner of the process.
- PID: Process ID.
- %CPU: CPU usage percentage.
- %MEM: Memory usage percentage.
- COMMAND: The command that started the process.
By entering the Flatpak instance’s namespace, you can perform tasks, run commands, and interact with the application’s environment directly.
Conclusion
Flatpak commands like flatpak ps
and flatpak enter
provide essential tools for managing and interacting with applications in a Flatpak environment. Whether you’re monitoring running instances or executing commands within a specific application’s sandbox, these commands offer flexibility and control over your Flatpak applications.
Extra’s
+------------------------+ +------------------------+
| Linux User | | Flatpak |
| | | |
| +------------------+ | | +----------------+ |
| | Terminal | | | | Sandbox | |
| +------------------+ | | +----------------+ |
| | | | | |
| +------------------+ | | +----------------+ |
| | | | | | | |
| | Application ( | | | | Application ( | |
| | e.g., Browser) | | | | e.g., Browser) | |
| | | | | | | |
| +------------------+ | | +----------------+ |
+------------------------+ +------------------------+
+---------------------+
| Linux User ||
| ||
| +-----------------+|
| | Home Directory ||
| | (Files) ||
| +-----------------+|
| ||
| +-----------------+|
| | User Processes || +---------------------+
| | (e.g., Shell)|| | Flatpak Instance |
| +-----------------+| | (Sandboxed) |
| || | +---------------+ |
| +-----------------+| | | Application | |
| | User Namespace||-------------| | Files | |
| | (IDs mapping) || | +---------------+ |
| +-----------------+| | | Dependencies | |
| || | | & Runtime | |
| +-----------------+| | +---------------+ |
| | Flatpak Process || | |
| | (inside NS) || +---------------------+
| +-----------------+|
+---------------------+
Try out some more commands for experimentation
$ flatpak ps
Instance PID Application Runtime Version
1 123 org.example.App org.freedesktop.Platform 20.08
2 456 com.another.app org.kde.Platform 21.04
3 456 com.another.app2 org.kde.Platform 23.11
Examples to practice
$ flatpak enter 3 pwd
$ flatpak enter 3 sh
$ flatpak enter 3 ls -lrt
$ flatpak enter 3 top
$ flatpak enter 3 python3
$ flatpak enter 3 whereis ls
$ flatpak enter 3 ls -lrt