From 68d9b8aad3e1f05487d497cd8a244091f06ee986 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Wed, 20 Aug 2025 11:33:37 -0500 Subject: [PATCH] notes on ps working dir --- get_pid.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/get_pid.go b/get_pid.go index ce5e18d..8d0f67c 100644 --- a/get_pid.go +++ b/get_pid.go @@ -5,6 +5,34 @@ import ( "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 + 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//cwd + This will show you where the cwd link points. +*/ + func main() { fmt.Println("Starting a 'sleep 15' command...")