LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-06-2011, 12:01 PM   #1
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Rep: Reputation: 16
sleep( ) call causes whole GNU Linux system to hang indefinitely


Anyone know the reason why a sleep( ) on a Redhat Linux OS would cause the system to indefinitely hang?

It's doing this every 10 or so calls in my program and I have to press the reboot button on my computer.

This is driving me nuts.

EDIT:

My program is reading from a UDP port that has messages sent to it 20 times per second. When I sleep I assume the internal UDP buffer is getting more and more filled.

Last edited by wtruong; 05-06-2011 at 03:47 PM.
 
Old 05-06-2011, 05:02 PM   #2
Ramurd
Member
 
Registered: Mar 2009
Location: Rotterdam, the Netherlands
Distribution: Slackwarelinux
Posts: 698

Rep: Reputation: 110Reputation: 110
why are you sure the sleep() is the cause? Because, in itself a sleep would/should not be the cause of your system hang(s).
What version of RedHat, and whatever else may applicable?
 
Old 05-07-2011, 04:40 PM   #3
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
Redhat Enterprise Linux 5.4.

I'll run it under valgrind on monday to see if anything is being corrupted.
 
Old 05-09-2011, 11:20 AM   #4
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If this is a userspace application, and it is reproducible, then I imagine someone in the kernel development community would like to know about it. No userspace application should be able to crash the OS.
--- rod.
 
Old 05-09-2011, 11:35 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by wtruong View Post
...
It's doing this every 10 or so calls in my program and I have to press the reboot button on my computer.
...
What else other than pressing the reboot button have you tried to do ?

How do you know that your system (i.e. the kernel, not your particular task) hangs ?
 
Old 05-09-2011, 11:35 AM   #6
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by wtruong View Post
My program is reading from a UDP port that has messages sent to it 20 times per second.
Could you clarify the statement above? Are you stating that messages are sent at a rate of 20 msg/sec to the socket, or that you read the port at a rate of 20 read/sec?

And more importantly, why are you using sleep()?

Last edited by dwhitney67; 05-09-2011 at 11:39 AM.
 
Old 05-09-2011, 01:09 PM   #7
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
Quote:
How do you know that your system (i.e. the kernel, not your particular task) hangs?
I know it hangs because it hangs. I can't do anything else but to reset the card. I can't SSH into it, the serial terminal doesn't respond, etc.

Quote:
Could you clarify the statement above? Are you stating that messages are sent at a rate of 20 msg/sec to the socket, or that you read the port at a rate of 20 read/sec?

And more importantly, why are you using sleep()?
My application is reading from a port that has 20 small messages / second sent to it. The sleep prevents it from reading the messages coming in. I need to use sleep because the hardware that the application is sending to needs time to process a message I send to it (Old hardware). I've since moved the code segment that uses sleep to another thread so that the application doesn't have any delay in reading the messages at 20 times per second and so far no system hangs.

I'm still curious to know why the sleep would cause the system to hang though. I'm assuming there are guards to prevent user space code from corrupting anything that sleep() relies on to recover? Can anyone enlighten me on how sleep() works on GNU/Linux?

The only other issue I've found on the internet regarding a similar issue is this:
http://www.daniweb.com/software-deve...threads/267684

Before anyone says that it can be a SIGALRM or alarm() issue, the GNU C Library states, "On the GNU system, it is safe to use sleep and SIGALRM in the same program, because sleep does not work by means of SIGALRM."

Source: http://www.gnu.org/s/hello/manual/libc/Sleeping.html

Last edited by wtruong; 05-09-2011 at 01:17 PM. Reason: New Information
 
Old 05-09-2011, 03:06 PM   #8
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,539

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Have you tested a simple program such as this? If so, did the system hang?
Code:
#include <unistd.h>

int main()
{
   sleep(1);
   return 0;
}
P.S. As was commented on earlier, I also find it hard to believe that a user-program, calling sleep(), would affect the entire OS.

Last edited by dwhitney67; 05-09-2011 at 03:08 PM.
 
Old 05-09-2011, 03:18 PM   #9
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
I commented out some code and put a sleep(1); return 0; in a while(1) loop, which each iteration reading one message from the port. Everything went fine. This leads me to believe that something may be corrupting addresses that sleep relies on.

I've yet to run valgrind, but will update as soon as I do.
 
Old 05-09-2011, 03:27 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by wtruong View Post
I know it hangs because it hangs. I can't do anything else but to reset the card. I can't SSH into it, the serial terminal doesn't respond, etc.
...
???

Do you have physical terminal and keyboard connected to the "hanging" computer ? Can you switch to another virtual console (e.g. Ctrl-Alt-F1 .. Ctrl-Alt-F6) ?
 
Old 05-09-2011, 03:35 PM   #11
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
There is a serial terminal connected to /dev/ttyS0 that is open and idle during the time of execution. When the system hangs the serial terminal is unresponsive. No kernel panic whatsoever as well.
 
Old 05-09-2011, 03:35 PM   #12
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
And, by the way, I remember that heavily loaded 4 core server with 16GB of RAM could be very unresponsive - it was taking several minutes to obtain 'ssh' response from it.

So, if your program leaks memory, so heavy swapping kicks in, you may feel the server is stuck, though in reality it isn't.
 
1 members found this post helpful.
Old 05-09-2011, 06:03 PM   #13
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
Memory usage and processor usage is very small/negligible. It doesn't even show up in top. Anyways, like I said I moved the function that had sleep in it to another thread and the system doesn't hang anymore.
 
Old 05-10-2011, 01:42 PM   #14
wtruong
Member
 
Registered: May 2009
Distribution: ubuntu
Posts: 35

Original Poster
Rep: Reputation: 16
Alright guys, I ran the program under helgrind and I found the problem. It was a deadlock in the kernel device driver and not the sleep. Thanks for the help guys.

Time to point fingers at the guy who wrote this.
 
Old 06-27-2011, 04:06 AM   #15
Kwarf
LQ Newbie
 
Registered: Jul 2008
Posts: 1

Rep: Reputation: 0
Quote:
Originally Posted by wtruong View Post
Alright guys, I ran the program under helgrind and I found the problem. It was a deadlock in the kernel device driver and not the sleep. Thanks for the help guys.

Time to point fingers at the guy who wrote this.
I'm experiencing similar problems. Which device drivers caused the problems on you system?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Gnu Free Call, the freedom to call out when you really need to LXer Syndicated Linux News 0 04-04-2011 10:10 AM
ftruncate64() system call stuck in uninterruptible sleep when resizing to large sizes DigiH Linux - Kernel 2 10-04-2010 04:49 AM
Sleep indefinitely abhijitd Linux - Newbie 1 02-16-2009 03:37 AM
LXer: Why I refuse to call it GNU/Linux LXer Syndicated Linux News 0 08-20-2007 06:12 AM
I am trying implement sleep in read system call problem sbharsha Programming 1 09-18-2005 11:48 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration