Apache Kafka and Zookeeper are important components of the Apache Kafka ecosystem that play a crucial role in the processing and management of large-scale distributed data.
To monitor and manage these processes effectively, it is important to know their Process ID (PID), which is a unique identifier assigned to each running process on a system. In this article, we will discuss how to find the PID of Apache Kafka and Zookeeper processes.
Using jps to find Kafka and Zookeeper Pid
The first step is to ensure that both Apache Kafka and Zookeeper are running on your system. Once you have confirmed that the processes are running, you can use the jps command to find their PIDs:
$ jps 33844 Jps 30568 Kafka 30012 QuorumPeerMain
As you can see, when you execute the jps
command, it lists all the JVM processes running on the machine along with their process IDs (PIDs). The output of the jps
command includes the name of the main class or the jar file, which helps you to identify the process and its purpose.
In our case we will focus on the following Processes:
- Kafka: This is the Kafka Broker
- QuorumPeerMain: This is Zookeeper Process
You can capture the ProcessId of those Processes in a variable. For example, to store the Kafka Process Id in the variable kafka_pid you can run the following:
kafka_pid=$(jps | grep Kafka | awk '{print $1}')
Using ps to find Kafka and Zookeeper Pid
Usually, the jps command is available as long as you jave a Java Runtime Environment in your machine. On the other hand, to find the PID of the Apache Kafka process with just the ps command, you can track the start up class, which is “kafka.Kafka”. Therefore, we can run the following command:
pid=$(ps aux | grep "kafka.Kafka" | grep -v grep | awk '{print $2}')
Then, if you check the value of $pid, you can see the ProcessId of Apache Kafka:
echo $pid 30568
To find the PID of the Zookeeper process, you can check the ProcessId for the Java Class org.apache.zookeeper.server.quorum.QuorumPeerMain. Therefore, you can run the following command:
pid=$(ps aux | grep "org.apache.zookeeper.server.quorum.QuorumPeerMain" | grep -v grep | awk '{print $2}')
Conclusion
Once you have obtained the PIDs of both Apache Kafka and Zookeeper processes, you can use them to monitor and manage these processes effectively. For instance, you can use the PIDs to kill or restart the processes if they are misbehaving or to check the system resources used by each process.
In conclusion, finding the PIDs of Apache Kafka and Zookeeper processes is an important aspect of managing these components effectively. By using the commands outlined in this article, you can quickly obtain the PIDs of these processes and use them to ensure that your Apache Kafka ecosystem is running smoothly.
Found the article helpful? if so please follow us on Socials