How To View The Open Files And Ports Associated With A Process On Macos

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.

  1. Open the Terminal application on your Mac by going to Applications > Utilities > Terminal, or using Spotlight search.
  2. Type the following command in the Terminal window and press Enter.

    lsof -i -P | grep -i "process_name"
  3. Replace “process_name” with the name of the process you want to view the open files and ports for.
  4. 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
  5. Press Enter to execute the command.
  6. The Terminal should now display a list of all the open files and ports associated with the specified process.
  7. The list will include the name of the file or port, the user who opened it, and the process ID (PID) of the process.
  8. 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
    
  9. 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.

  1. To view the open files and ports associated with a process using Activity Monitor on macOS, follow these steps.
  2. Open Activity Monitor. You can find it in the Utilities folder within the Applications folder, or by using Spotlight search.
  3. 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.
  4. Once you have found the process, select it by clicking on it.
  5. Click on the “Inspect” button ( button with the small character i ) in the toolbar top left corner.
  6. In the new window that appears, click on the “Open Files and Ports” tab.
  7. Here you can view all the files and ports that the process has open.
  8. The list includes the file path, file descriptor, and port number.
  9. Note: You need to have admin privileges to view all open files and ports associated with a process.
  10. Also, some processes may have a large number of open files and ports, so the list may be long and difficult to read.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.