Sometimes, we launch a service on Linux and get a message that another process already uses the same port. In such situations, a practical solution could involve terminating the process associated with the occupied port number. This will help free up system resources.
We can terminate a process running on a particular port as follows:
List any process running on that particular port (for example, 8890
):
lsof -i:8890
Terminate any process running on that particular port (for example, 8890
):
kill $(lsof -i:8890 -t)
This command will terminate any process running on port 8890
.
Note: By default, the
kill
command sends the soft signal, which will terminate the process or allow it to clean up before exiting.
We can send an immediate termination signal to the process as follows:
kill -9 $(lsof -i:8890 -t)
kill
: Command to terminate the process
-9
: Forcefully (immediate termination)
lsof
: List related processes
-i
: Specify the port number
-t
: List process ID (PID) only
That's how we can terminate a process running on a particular port in Linux.
Let's try to terminate a process running on a particular port in the provided terminal by following these steps:
Copy the given command kill -9 $(lsof -i:8890 -t)
.
Hover over the "Click to Connect..." space and click to make the session active.
Paste the copied command and press "Enter."
Note: Once the command is executed, the terminal will promptly revert to its original state. This behavior indicates the correct functionality of the command, as our terminal session operates on port
8890
.
Unlock your potential: Linux series, all in one place!
To continue your exploration of Linux, check out our series of Answers below:
How to terminate a process running on particular port in Linux?
Learn how to terminate a process on a specific port in Linux using kill -9 $(lsof -i:<port> -t)
to free up resources.
How to create Symlink in Linux?
Learn how a symlink in Linux creates a shortcut to a file or folder, aiding navigation and manipulation.
What are soft and hard links in Unix/Linux?
Learn how soft links reference file paths as shortcuts, while hard links point directly to file inodes, ensuring data retention even after deletion.
How to show current working directory's path in linux
Learn how to use the pwd
command in Linux to display the current directory path, with -L
for logical paths and -P
for physical paths.
Free Resources