Information about services/processes & PID
The compiled commands listed below utilizes a few tools: ps, ss, lsof & pgrep. More details about these tools can be found in the individual pages above.
** TO CONTEMPLATE ABOUT THE COMMANDS WHICH REQUIRES SUDO
Find processes by service name
pgrep flags usage:
-l: List the process name as well as the process ID
Retrieve information about a specific PID
ps flags usage:
-p: To select by PID
Identify the port number related to a PID or service name
Method 1: Using ss
ss flags usage:
-p: Show processes using sockets
Note: In the example below, the command grep -P ':\d{1,}'
essentially uses the Perl regex syntax matching to look for all values with the format of :<1 or more digits> such as :4000, :8000, etc.
Method 2: Using lsof
lsof flags usage:
-i: To only list the addresses associated with an internet address (prevent overload of information that are not relevant)
-P: Prevent conversion of port numbers to port names. For example, listing would appear as :53 instead of :domain
-n: Prevent conversion of network numbers to host names. For example, listing would appear as 127.0.0.1 instead of localhost
Direct method to look for port numbers relating to a service
Look for listening sockets related to a PID or service name
The first portion of the command retrieves all listening sockets.
While the second portion narrows the output down to only the specified PID or service name.
Final command
Last updated