notes on ps working dir

This commit is contained in:
Jeff Carr 2025-08-20 11:33:37 -05:00
parent 25ae0bd31c
commit 68d9b8aad3
1 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,34 @@ import (
"os/exec" "os/exec"
) )
/*
To see the PID, command, and current working directory for all processes, you can run:
1 ps -eo pid,cmd,cwd
Explanation
* -e: Selects every process on the system.
* -o pid,cmd,cwd: Specifies a user-defined format.
* pid: Shows the Process ID.
* cmd: Shows the command with its arguments.
* cwd: Shows the current working directory of the process.
Alternative for a Specific Process (Linux)
If you already know the PID and just want to find its working directory, there are two even more direct methods on Linux:
1. Using the `pwdx` command:
1 pwdx <PID>
This will print only the CWD for that specific process.
2. Checking the `/proc` filesystem:
The CWD is exposed as a symbolic link. You can read it with ls or readlink:
1 ls -l /proc/<PID>/cwd
This will show you where the cwd link points.
*/
func main() { func main() {
fmt.Println("Starting a 'sleep 15' command...") fmt.Println("Starting a 'sleep 15' command...")