Link to home
Start Free TrialLog in
Avatar of codey-06
codey-06Flag for Afghanistan

asked on

looping

Hi I am writing a kernel module.

I need a continuous loop that will look for tcp traffic and read from skb to store each source ip address from ip_hdr->saddr into an array

I can get it to read packets one at a time but I need it to loop, but when I try to implement a continuous loop the system crashes/hangs.

Can anyone offer any advice/possible fixes?

Cheers
Avatar of Anthony2000
Anthony2000
Flag of United States of America image

Here is an example of using a thread in the kernel module.

http://www.scs.ch/~frey/linux/kernelthreads.html

I think your problem might be that your loop is running and using all available kernel/process time. Thus, giving the result of maybe locking up your machine. Is that what is happening?
Avatar of codey-06

ASKER

Hi yes you are correct, the loop is using up all the kernel resources.  Is there a quick fix?
Have you tried some kind of sleep (I cannot remember the API call). This may give the OS and other processes time to run.
Thank you. If anyone could offer a bit more help it would be very much appreciated?
SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Also, take a look at the functions:
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout (signed long timeout);

See chapter 7 of the book link I provided.
Brilliant thank you