Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8392917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T19:38:49+00:00 2026-06-09T19:38:49+00:00

I’ve made a packet sniffer using JNetPcap library. It’s a .jar that is executed

  • 0

I’ve made a packet sniffer using JNetPcap library. It’s a .jar that is executed from another application that monitors the system resources (RAM, Disk usage, active network interfaces, running processes, etc). I want the sniffer to close itself when the monitor application is terminated (by the user or not) and I thought about creating a file with the monitor app and locking it using fileLock. Then on every loop of the sniffer I’d check if the file is still locked and if it’s not (meaning the monitor app terminated), then I’d call System.exit(0);

The problem is that the amount of nonpaged kernel memory usage (actually, it’s not just nonpaged kernel memory) goes up really fast when they’re both executing. It doesn’t happen when I execute them individually.

It also doesn’t happen when I run them simultaneously, but with the following piece of code in the sniffer app commented (responsible for checking whether the file created by the monitor is still locked)

        private void checkReleasedLock() throws IOException{
            File file = new File("config\\file.lock");
            FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
            FileLock lock = null;

            try {
                 lock = channel.tryLock();

                 if(lock != null){ //It acquired the lock => the other application is terminated.
                     System.exit(0);
                 } else {
                     file = null;
                     channel = null;
                     lock = null;
                 }
            } catch (Exception e) {
                file = null;
                channel = null;
                lock = null;
            }
        }

Just to show you the increase in memory usage, this is the output of the monitor app that logs the system resources:

######################################
# Beginning log: 2012-08-03 10:14:26 #
######################################
__________
RAM USAGE:

Total: 2040 MB
Free: 1260 MB (63.31 %)
Used: 720 MB (36.69 %)

Swap total: 4125 MB
Swap used: 1104 MB
Swap free: 3021 MB

Kernel Memory Total: 75876 KB
Paged: 52536 KB
Nonpaged: 23340 KB

And a couple of hours later…

######################################
# Beginning log: 2012-08-03 12:14:27 #
######################################
__________
RAM USAGE:

Total: 2040 MB
Free: 1000 MB (50.37 %)
Used: 980 MB (49.63 %)

Swap total: 4125 MB
Swap used: 1307 MB
Swap free: 2818 MB

Kernel Memory Total: 213724 KB
Paged: 173724 KB
Nonpaged: 40000 KB

Is something wrong with that code? Could it be the cause of the memory leak?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T19:38:50+00:00Added an answer on June 9, 2026 at 7:38 pm

    Is something wrong with that code?

    It looks like each time you call that method you will create a FileChanel object that is not closed. Assigning null doesn’t cause anything to be closed.

    You should code it like this to ensure that the FileChanel is always closed:

       private void checkReleasedLock() throws IOException {
            File file = new File("config\\file.lock");
            FileChannel channel = new RandomAccessFile(file, "rw").getChannel();
            FileLock lock;
    
            try {
                lock = channel.tryLock();
                if (lock != null) {
                    System.exit(0);
                }
            } finally {
                channel.close();
            }
        }
    

    Note that I’ve also fixed a bug that caused all Exceptions to be squashed.

    Could it be the cause of the memory leak?

    Yes, it could be. With the code in its original form, the open file channels would only get closed when the objects were finalized by the Java garbage collector. Until then, each one will be tying down operating system resources, and that could well explain the increased unpaged kernel memory usage.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.