Entries Written By Michael
Java, Spring Boot, and React Boilerplate Project
I needed a project boilerplate that uses Java, Spring Boot on the back-end, and React on the front-end. Basically a combined Java, Spring Boot, and React Boilerplate Project. I’ll detail the setup in a later post. You can find the code here on GitHub: https://github.com/btaz/jaws.
Get the Current Working Directory in Java
How do you get the current working directory in Java? There are a few different ways of getting the the current working directory. System Property user.dir The System class contains properties that describes the configuration of the current working environment. The property that returns the current working directory is “user.dir”. String userDir = System.getProperty(“user.dir”);System.out.println(“The current …
The Complete Maven pom.xml Structure Documentation
Maven is a tool for building Java applications. It has a pom.xml file that contains all the build instructions as well as a list of project dependencies. The pom.xml file has a bewildering amount of configurable options. The complete Maven pom.xml structure documentation (project descriptor file) is here on the Maven web site. This page …
Find the Process Listening to Port on Mac OS X
How to Find the Process Listening to Port on Mac OS X
Step-by-Step
To find the process that is listening to a port on Mac OS X, we’ll use the lsof command to find the process ID (PID), and the ps command to show the name.
Find the Process ID (PID)
There are two different ways we can use to find the process that is listening to a port on Mac OS X.
Find the Process ID (PID) Using lsof
Using the lsof command we can find the process ID (PID) for a specific port that is in a LISTEN state. In a terminal type the following and replace the “<port-number>” with our port number.
lsof -nP -iTCP -sTCP:LISTEN | grep <port-number>
This generates output that looks like this:
node 63851 pogo 27u IPv6 0xfded4774db1c601f 0t0 TCP *:9999 (LISTEN)
In the output above the PID (process ID) is the second value, in this example output the process ID (PID) is “63851”. This command will also print out the port number, which is 9999 in the above output example.
Find the Process ID (PID) Using netstat
Using the nestat command we can find the process ID (PID) for a specific port. In a terminal type the following and replace the “<port-number>” with our port number.
netstat -anv | grep <port-number>
This generates output that looks like this:
tcp46 0 0 *.9999 *.* LISTEN 131072 131072 63851 0 0x0100 0x00000106
In the output above the PID (process ID) is the ninth value (the fourth value from the end), in this example output the process ID (PID) is “63851”. This command will also print out the port number, which is 9999 in the above output example.
Find the Process Name
We can now use the process status command ps to display the process name for the process ID (PID).
ps -Ao user,pid,command | grep -v grep | grep <PID>
This generates output that looks like this:
mymachine 63851 the-process
In the output above the process name is the last value “the-process.” Now we know the name of the process that is listening to the port. The reason as to why the grep command is listed twice is to avoid displaying the process ID (PID) for the grep command itself.
Other Useful Commands
How to Kill or Stop the Process by PID
You can kill the process by process ID (PID) using the kill command. Replace “<PID>” with the process ID from lsof or netstat.
kill -9 <PID>
The lsof Command
The lsof command lists open files. Network sockets count as files, so each open network socket, either listening or actively in use is listed by lsof. In addtion you can run the man lsof command to display all the different options for lsof.
man lsof
lsof can take a very long time to execute, so I suggest that you use -n (inhibits the conversion of network numbers to host names for network files) and -P (inhibits the conversion of port numbers to port names for network files) to speed it up.
lsof -nP
Don’t be a Tool
Developers often associate their identity with a programming language or a framework. I’m a Java developer, I’m a JavaScript developer, I’m a React developer, or I’m a back-end developer. It’s an understandable perspective, however, if you asked a carpenter what he does for a living, and he answered, “I’m a user of hammers,” it wouldn’t …
Unexpected Token ‘<' client_bundle.js:1
Unexpected Token ‘<‘, I got this message while I was working on one of my React / Webpack projects on Churgle, a website that has tools and utilities. The error in my case manifested itself on single a page reachable through a React route. It didn’t matter if I changed the order of any routes, …
External File Sort In Java
How do you sort a lot of data in Java? It’s easy to sort small amounts of data in memory. For example if your data is in a List object, then with the help of the Collections class you can easily sort the data. You can provide a custom Comparator to control in what order your data …
Los Angeles Hadoop Users Group- LA-HUG
LA now has its own HUG. The first meetup will be held on Wednesday 2/9/2011. This is a great opportunity for anyone in the Los Angeles area with interest in Hadoop and related technologies to discuss and meet. The first talk is: “Operationalizing Hadoop” with Charles Zedlewski (Cloudera’s VP Product) http://www.meetup.com/LA-HUG/
fatal: The remote end hung up unexpectedly
I committed changes to my GIT project, tried to push them to the remote server (git push) and got the following cryptic error message: fatal: The remote end hung up unexpectedly The GitFaq states that: Git push fails with “fatal: The remote end hung up unexpectedly”? If, when attempting git push, you get a message …
Hadoop World
I just came back from the Hadoop World conference in New York and I have to say that it was quite exciting. Processing huge amounts of data used to be a problem for just a few companies like Google, Yahoo, Facebook and a few others, but has now become a problem for many. The conference …
Recent Comments