MoonPoint Support Logo

 


Shop Amazon Warehouse Deals - Deep Discounts on Open-box and Used ProductsAmazon Warehouse Deals



Advanced Search
April
Sun Mon Tue Wed Thu Fri Sat
           
13
24 25 26 27 28 29
30            
2017
Months
AprMay Jun
Jul Aug Sep
Oct Nov Dec


Thu, Apr 13, 2017 10:37 pm

Counting the number of instances of a process on Microsoft Windows

If you need to know the number of instances of a particular process running on a Microsoft Windows system, you can see all of the instances by using the tasklist /fi option to filter the output from the tasklist command by imagename. E.g., I could view information on the PuTTY processes currently running on a Windows system with the command below:

C:\>tasklist /fi "IMAGENAME eq putty.exe"

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
putty.exe                    57380 Console                    1      4,404 K
putty.exe                    49012 Console                    1      3,584 K
putty.exe                    72424 Console                    1      3,060 K
putty.exe                     8028 Console                    1      3,992 K
putty.exe                    96136 Console                    1      4,632 K
putty.exe                   102860 Console                    1      2,936 K
putty.exe                    87200 Console                    1      4,572 K
putty.exe                   121020 Console                    1      2,908 K
putty.exe                   100348 Console                    1      4,228 K
putty.exe                    81692 Console                    1      3,068 K
putty.exe                   118448 Console                    1      2,020 K
putty.exe                   102856 Console                    1      2,544 K
putty.exe                   126692 Console                    1      4,332 K
putty.exe                   133004 Console                    1      3,664 K
putty.exe                   136344 Console                    1      5,204 K
putty.exe                   126408 Console                    1      3,620 K
putty.exe                   114896 Console                    1      2,880 K
putty.exe                   132868 Console                    1      2,972 K
putty.exe                   133048 Console                    1      3,860 K
putty.exe                   139232 Console                    1      3,732 K
putty.exe                   132756 Console                    1      2,928 K
putty.exe                   136484 Console                    1      3,576 K
putty.exe                   147964 Console                    1      2,960 K
putty.exe                   142800 Console                    1      6,136 K
putty.exe                   139192 Console                    1      2,952 K
putty.exe                    32748 Console                    1      2,896 K
putty.exe                    78048 Console                    1      3,596 K
putty.exe                   113756 Console                    1      3,304 K
putty.exe                    62572 Console                    1      4,120 K
putty.exe                    17620 Console                    1      3,376 K
putty.exe                    36156 Console                    1      1,756 K
putty.exe                    86144 Console                    1      3,528 K
putty.exe                     4600 Console                    1      4,440 K
putty.exe                    46532 Console                    1      6,048 K
putty.exe                    49572 Console                    1      2,884 K
putty.exe                    69560 Console                    1      3,268 K
putty.exe                    67948 Console                    1      4,120 K
putty.exe                   139328 Console                    1      2,948 K
putty.exe                    25888 Console                    1      6,552 K
putty.exe                   119096 Console                    1      3,676 K
putty.exe                    48572 Console                    1      3,084 K
putty.exe                   132724 Console                    1      6,720 K
putty.exe                   123480 Console                    1      2,944 K
putty.exe                   148548 Console                    1      3,704 K
putty.exe                    46280 Console                    1      7,860 K
putty.exe                   146844 Console                    1      4,648 K
putty.exe                    47612 Console                    1      6,548 K
putty.exe                    84404 Console                    1      3,060 K
putty.exe                    35920 Console                    1     15,780 K
putty.exe                    91288 Console                    1     14,832 K
putty.exe                   115612 Console                    1      5,216 K
putty.exe                    85164 Console                    1      6,972 K
putty.exe                    22796 Console                    1      9,640 K
putty.exe                    87868 Console                    1     15,596 K

C:\>

If I don't want to manually count the instances, I can use the find command as shown below:

C:\>tasklist /fi "IMAGENAME eq putty.exe" | find /i /c "putty.exe"

54

C:\>

The /i option to the find command tells find that the case of letters is unimportant, i.e., it should match either lowercase or uppercase letters. The /c option instructs it to display a count for the number of matching lines it found.

If I want to put the count in a variable in a batch file, I can use the the command noted in Setting a Variable to be the Output of a Command.

Alternatively, you can use a Windows Management Instrumentation Command-line (WMIC) command. E.g.:

C:\>wmic process where name="putty.exe" get name | find /c "putty.exe"
54

C:\>

Related articles:

  1. Obtaining a list of running processes and their associated PIDs Date: April 8, 2017
    MoonPoint Support

[/os/windows/commands] permanent link

Once You Know, You Newegg AliExpress by Alibaba.com

Shop Amazon Local - Subscribe to Deals in Your Neighborhood

Valid HTML 4.01 Transitional

Privacy Policy   Contact

Blosxom logo