To view the open files and ports associated with a process on macOS, you can use the Terminal application and run the utility commands introduced in this article. You can also find the open files and ports associated with a process in activity monitor. This article will introduce them to you one by one.
1. How To Get macOS Process Associated Files And Ports In Command Line.
- Open the Terminal application on your Mac by going to Applications > Utilities > Terminal, or using Spotlight search.
- Type the following command in the Terminal window and press Enter.
lsof -i -P | grep -i "process_name"
- Replace “process_name” with the name of the process you want to view the open files and ports for.
- For example, if you want to view the open files and ports for the Safari browser, you would type the command.
lsof -P | grep Safari
- Press Enter to execute the command.
- The Terminal should now display a list of all the open files and ports associated with the specified process.
- The list will include the name of the file or port, the user who opened it, and the process ID (PID) of the process.
- For example, the result may look like below.
Safari 1193 jerry 15r REG 1,7 56150 40929 /private/var/db/nsurlstoraged/dafsaData.bin Safari 1193 jerry 16r REG 1,7 215992 58549 /Library/Application Support/CrashReporter/SubmitDiagInfo.domains Safari 1193 jerry 17u REG 1,7 49152 45295 /Users/jerry/Library/Safari/AutoFillCorrections.db Safari 1193 jerry 18u REG 1,7 0 45297 /Users/jerry/Library/Safari/AutoFillCorrections.db-wal Safari 1193 jerry 19u REG 1,7 36864 45298 /Users/jerry/Library/Safari/CloudAutoFillCorrections.db Safari 1193 jerry 20u REG 1,7 0 45306 /Users/jerry/Library/Safari/CloudAutoFillCorrections.db-wal
- This command will give you a better understanding of which files and ports a process is using, which can be helpful in troubleshooting or optimizing system performance.
2. How To Use Activity Monitor To View The Open Files And Ports Associated With A macOS Process.
- To view the open files and ports associated with a process using Activity Monitor on macOS, follow these steps.
- Open Activity Monitor. You can find it in the Utilities folder within the Applications folder, or by using Spotlight search.
- Find the process you want to view. You can sort the list by Process Name, CPU Usage, Memory Usage, or other criteria by clicking on the column headers.
- Once you have found the process, select it by clicking on it.
- Click on the “Inspect” button ( button with the small character i ) in the toolbar top left corner.
- In the new window that appears, click on the “Open Files and Ports” tab.
- Here you can view all the files and ports that the process has open.
- The list includes the file path, file descriptor, and port number.
- Note: You need to have admin privileges to view all open files and ports associated with a process.
- Also, some processes may have a large number of open files and ports, so the list may be long and difficult to read.