Solved

Program getting too high of a priority

Posted on 2004-08-19
7
218 Views
Last Modified: 2010-04-22
I have a packet sniffer that uses libpthread and libpcap. There is one while(1) loop in one thread, but I call a sleep(300) at the beginning of the loop. The next thread basically just sets up the callback for libpcap. I noticed that when doing a 'top' listing, my threads are all listed at the top of the list. I am using the default scheduling for the threads. I noticed that when doing a tcpdump, it almost never gets put at the top of the list. How can I reduce the priority of my threads without dropping packets?

-ryan
0
Comment
Question by:dignified
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11849489
>How can I reduce the priority of my threads without dropping packets?

Unless you are facing some problems due to this issue ,i.e. unless it is affecting your functionality, I would suggest that you leave it alone.

Also, if you did not explicitly set the scheduling and priority of your threads, they have the same default priority as almost every other process.
0
 

Author Comment

by:dignified
ID: 11849551
That is what I thought too. I just don't understand why they would be having such a higher priority than tcpdump when they do almost the same thing. and use the same library.
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11849560
It could be that tcpdump sets itself at a lower priority but most likely there is no priority isse involved here. What you see in top table is periodic snapshot and the sleeping task is anyway never in runnable queue so it will not execute at all !!! System may keep a tab on time at which to wake it up and updating a counter, but thats about all.
0
 
LVL 1

Expert Comment

by:DJSara
ID: 11913782
Instead of using 'sleep' in the while(1) loop, use 'select' or 'pselect' system call on the socket descriptor. That way you can make sure that you will not drop packets.
 It is not because of higher priority, but because of the infinite loop, your process uses a lot of CPU time even when there is no packets arriving and hence listed above tcpdump in top.  By using 'select' or 'pselect', your process will be blocked waiting for packets in the socket descriptor and hence won't utilize the CPU time.
0
 
LVL 2

Accepted Solution

by:
gysbert1 earned 500 total points
ID: 11987383
I you're using pcap (presumably opened with pcap_open_live), if you have your main loop as follows:
      const u_char *uchar;
      struct pcap_pkthdr packet;
      while ((uchar = pcap_next(pcap, &packet))) {
      //... process packet
      }
it does not use up any CPU unless you're getting LOTS of ethernet packets and doing heavy processing on them in that loop. pcap_next effectively does a select internally, so the call only returns when a packet arrives to 'wake' your process in the linux kernel process scheduler.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question