I want to grep the the PID of last running process in Windows. I am running the command in the background.
How do I get the PIDs of these commands?
Task Manager can be opened in a number of ways, but the simplest is to select Ctrl+Alt+Delete, and then select Task Manager. In Windows, first click More details to expand the information displayed. From the Processes tab, select Details to see the process ID listed in the PID column.
How to get PID using Task Manager. Press Ctrl+Shift+Esc on the keyboard. Go to the Processes tab. Right-click the header of the table and select PID in the context menu.
Process IDs, in the first place, are usually allocated on a sequential basis, beginning at 0 and rising to a maximum value which varies from system to system. Once this limit is reached, allocation restarts at 300 and again increases.
Possibly by tracking them.
When you start the first instance, you could use the tasklist
command with the filter by the image name (see tasklist /?
) to find the PID, which you would then store somewhere. (The output of tasklist
can be parsed with the FOR /F
command, see FOR /?
for more info.)
Then, when you run the second instance, you do the same, but additionally filter out the stored PID (for example, using FIND /V
, see FIND /?
for more help), so you get only new instance's PID. Store it as well to use later like the first one when you need to run a third instance.
You can use wmic to launch the processes and get the pid from that. I've posted what I use for this as an answer to a similar question here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With