To get the PID of the last executed command type: echo "$!" Store the pid of the last command in a variable named foo: foo=$! Print it, run: echo "$foo"
...
How to return pid of a last command in Linux.
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | No |
Requirements | Linux or Unix terminal |
Category | Linux shell scripting |
- How do I find the process ID in Unix?
- How can I get process ID details?
- How to get all process ID in Linux?
How do I find the process ID in Unix?
A process is nothing but running instance of a program and each process has a unique PID on a Unix-like system. The easiest way to find out if process is running is run ps aux command and grep process name. If you got output along with process name/pid, your process is running.
How can I get process ID details?
The ps -p <PID> command is pretty straightforward to get the process information of a PID. Alternatively, we can also access the special /proc/PID directory to retrieve process information.
How to get all process ID in Linux?
You need to use the ps command. It provides information about the currently running processes, including their process identification numbers (PIDs). Both Linux and UNIX support the ps command to display information about all running process.