Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PID of last running process in Windows

I want to grep the the PID of last running process in Windows. I am running the command in the background.

  • start "Window Title" /b "c:\Program Files\Wireshark\tshark.exe" -i 1 -w file1.pcap
  • start "Window Title" /b "c:\Program Files\Wireshark\tshark.exe" -i 1 -w file2.pcap

How do I get the PIDs of these commands?

like image 763
user87005 Avatar asked Nov 09 '11 06:11

user87005


People also ask

How do I find the PID of a process in Windows?

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 do I find the PID of a running program?

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.

Are Windows PIDs sequential?

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.


2 Answers

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.

like image 161
Andriy M Avatar answered Sep 20 '22 19:09

Andriy M


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.

like image 33
kybernetikos Avatar answered Sep 17 '22 19:09

kybernetikos