How to use the command 'tasklist' (with examples)
- Windows
- December 25, 2023
The ’tasklist’ command is a command-line utility in Windows that allows you to display a list of currently running processes on a local or remote machine. It can be used to gather information about the processes running on a system, such as their process ID (PID), memory usage, and status.
Use case 1: Display currently running processes
Code:
tasklist
Motivation: This use case is helpful when you want to get a quick overview of the processes currently running on your machine. It can be particularly useful when troubleshooting, as it allows you to identify any unexpected or resource-intensive processes.
Explanation: The tasklist command without any arguments simply displays a list of currently running processes. It provides information such as the process ID (PID), session name, session number, memory usage, and process name.
Example output:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 904 K
smss.exe 276 Services 0 464 K
csrss.exe 360 Services 0 5,324 K
Use case 2: Display running processes in a specified output format
Code:
tasklist /fo table|list|csv
Motivation: By default, the ’tasklist’ command displays the process list in a tabular format. However, you may prefer to use a different output format depending on your needs. This use case allows you to customize the format in which the process list is displayed.
Explanation: The ‘/fo’ option followed by ’table’, ’list’, or ‘csv’ specifies the desired output format for the process list. ‘Table’ displays the list in a tabular format, ’list’ displays it in a list format, and ‘csv’ outputs the list in comma-separated values (CSV) format.
Example output (using ‘/fo table’):
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 904 K
smss.exe 276 Services 0 464 K
csrss.exe 360 Services 0 5,324 K
Use case 3: Display running processes using the specified .exe or .dll file name
Code:
tasklist /m module_pattern
Motivation: Sometimes, you may want to filter the process list based on a specific executable (.exe) or dynamic link library (.dll) file name. This use case allows you to narrow down the process list and find processes related to a particular file.
Explanation: The ‘/m’ option followed by ‘module_pattern’ filters the process list to only display processes that have module names matching the specified pattern. The module pattern can include wildcard characters, such as ‘*’ (matches any number of characters) and ‘?’ (matches a single character).
Example output:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
chrome.exe 1234 Console 1 100,000 K
firefox.exe 5678 Console 1 200,000 K
Use case 4: Display processes running on a remote machine
Code:
tasklist /s remote_name /u username /p password
Motivation: In some cases, you may need to retrieve the process list from a remote machine. This use case allows you to connect to a remote machine using the specified username and password, and display the running processes on that machine.
Explanation: The ‘/s’ option followed by ‘remote_name’ specifies the remote machine name or IP address. The ‘/u’ and ‘/p’ options are used to provide the username and password for authentication on the remote machine.
Example output:
Image Name PID Session Name Session# Mem Usage
========================= ======== ================ =========== ============
System Idle Process 0 Services 0 8 K
System 4 Services 0 904 K
smss.exe 276 Services 0 464 K
csrss.exe 360 Services 0 5,324 K
Use case 5: Display services using each process
Code:
tasklist /svc
Motivation: This use case is useful when you want to determine which services are associated with each running process. It provides insight into how processes are related to the services running on the system.
Explanation: The ‘/svc’ option displays the services hosted by each process in the process list. It shows the service name associated with each process, making it easier to identify the relationship between processes and services.
Example output:
Image Name PID Services
========================= ======== ================
System Idle Process 0 N/A
System 4 N/A
smss.exe 276 N/A
csrss.exe 360 N/A
Conclusion:
The ’tasklist’ command is a versatile tool for displaying information about running processes in Windows. Whether you need to get a general overview of the processes on your machine, filter the list based on specific criteria, or gather information about services associated with each process, ’tasklist’ has you covered. By understanding the various use cases and their corresponding command-line arguments, you can effectively leverage the power of ’tasklist’ in your system administration and troubleshooting tasks.