notes on ps working dir
This commit is contained in:
parent
25ae0bd31c
commit
68d9b8aad3
28
get_pid.go
28
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 <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() {
|
||||
fmt.Println("Starting a 'sleep 15' command...")
|
||||
|
||||
|
|
Loading…
Reference in New Issue