Score:0

Efficiently get PID's in certain ports from java

jp flag

I know sudo lsof -t -i:{port} will give the list of PID's involved in that port and I can run this command via java by Runtime.getRuntime.exec() command. But the thing is I have thousands of thread running and every thread is executing this command with around 10s intervals which results in approximately 100+ total execution per second of this command alone which is taking a lot of server resources+time and load average is getting a rocket spike causing the program halt & crash.

What is the efficient way to do so in this type of scenario?

Score:0
jp flag

I solved it anyway and I had to get PID from around all 65500 ports and save it in hashmap for later usage in the interval of around every 10 secs. I made it done within 2-2.1 secs while 30,000 ports were active. I used "ps -aux" command for getting all active PID,PORT tuples at a time and then insert to hashmap after parsing (runtime parsing of command output and simultaneous insertion to hashmap).

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.