Skip to content

stellarthemes/whatport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

whatport

whatport is a small POSIX shell script that shows which processes are listening on a port. It can also send a signal to those processes, then verify whether the processes exited and whether the port is still in use.

Requirements

  • A POSIX-compatible shell such as /bin/sh
  • Either lsof or ss
  • Standard Unix utilities used by the script:
    • ps
    • kill
    • sed
    • sort
    • wc
    • sleep

Notes:

  • lsof is preferred when available because it provides clearer process details.
  • On some systems, seeing full process information may require sudo.
  • The script checks TCP listeners in LISTEN state and also shows UDP sockets bound to the port.

Installation

Make the script executable:

chmod +x whatport

Run it from this directory:

./whatport 3000

If you want to use it from anywhere, move it into a directory on your PATH, for example:

cp whatport /usr/local/bin/whatport
chmod +x /usr/local/bin/whatport

Usage

whatport PORT
whatport -k [-y] [-s SIGNAL] PORT

Examples:

whatport 3000
whatport --kill 3000
whatport -k -y 3000
whatport -k -y -s KILL 3000

Options

  • -k, --kill Send a signal to processes listening on the port.

  • -y, --yes Skip the confirmation prompt before killing.

  • -s, --signal SIGNAL Signal to send when killing. Default is TERM.

  • -h, --help Show built-in help text.

What It Does

When you run:

whatport 3000

the script:

  1. Validates that 3000 is a valid port number.
  2. Finds processes listening on that port.
  3. Prints process details.

When you run:

whatport -k 3000

the script:

  1. Shows the current listeners.
  2. Prompts for confirmation unless -y is used.
  3. Sends the requested signal to the matching PID or PIDs.
  4. Checks whether those PIDs are still running.
  5. Checks whether the port is still in use.

It exits successfully only when the kill path completes and the original PIDs are gone and the port is no longer in use.

Exit Behavior

  • 0 on successful lookup when listeners are found
  • 0 on successful kill and verification
  • 1 when no listeners are found, arguments are invalid, required tools are missing, or the kill/verification step fails

Examples

Show what is listening on port 8080:

./whatport 8080

Kill the listener on port 8080 and confirm interactively:

./whatport -k 8080

Force kill without prompting:

./whatport -k -y -s KILL 8080

Troubleshooting

  • If you get no process details, try running with sudo.
  • If the script says no listeners were found, verify the service is actually bound to that port.
  • If the port closes but the process remains alive, the script treats that as a failed kill verification.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages