LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 04-13-2008, 06:27 PM   #1
deathonator
LQ Newbie
 
Registered: Apr 2008
Posts: 2

Rep: Reputation: 0
nanosleep() command


I have used usleep(), but nanosleep has a different syntax. I see it has the form:

int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);

I'm not sure why they use a struct instead. I have tried nanosleep(1000000, NULL), but I'm not sure if that's right and doesn't seem to work. I haven't been able to find any helpful examples online either.

Thanks,
Bryan
 
Old 04-14-2008, 11:41 AM   #2
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 366
Blog Entries: 1

Rep: Reputation: 44
I haven't programmed any C in a while, so you might have to tweak this a little to get it to work, but basically, what you are doing wrong is trying to pass an int where a struct is expected ...

You need to

Code:
#include <time.h>

...
...

int seconds = 10;
long int nanosecs = 1500;

struct timespec foo;
foo.tv_sec = (time_t) seconds;
foo.tv_nsec = nanosecs;


...
...
nanosleep(&foo, NULL);

i.e. You need to pass it a pointer to a struct, not an integer value.

(see man nanosleep for details)
 
  


Reply



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
Is there a single command to list all hardware installed (command line)? davee Linux - Hardware 6 02-28-2009 07:19 PM
Translating windows pscp command to linux scp command help robward Linux - General 2 01-17-2008 06:02 AM
startx command in FC7 reverts me back to the command prompt sriram87 Linux - Newbie 5 01-03-2008 11:18 PM
nanosleep() problem ebatista Programming 10 01-04-2005 01:01 AM
about nanosleep() dummyagain Programming 4 10-01-2003 05:53 PM

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

All times are GMT -5. The time now is 09:51 PM.

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