Name

nanosleep - pause execution for a specified time

Library

libc.lib

Synopsis

  #include <time.h>
  int nanosleep (const struct timespec *rqtp, struct timespec *rmtp);

Return values

If the nanosleep system call returns because the requested time has elapsed, the value returned will be zero.

If rmtp is non- NULL, the timespec structure it references is updated to contain the unslept amount (the request time minus the time actually slept).


Detailed description

The nanosleep system call causes the process to sleep for the specified time. Currently only microsecond sleep resolution can be obtained.


Examples

/**
  * Detailed description: Sample usage of nanosleep system call.
**/
#include <stdio.h>
#include <time.h>
int main()
{
 struct timespec tim, tim2;
   tim.tv_sec = 1;
   tim.tv_nsec = 500;
   if(nanosleep(&tim , &tim2) < 0 )   {
      printf("Nano sleep system call failed \n");
      return -1;
   }
   printf("Nano sleep successfull \n");
  return 0;
}

         

Output

Nano sleep successfull

         


Errors

The nanosleep system call fails if:
[EFAULT]
  Either rqtp or rmtp points to memory that is not a valid part of the process address space.
[EINTR]
  The nanosleep system call was interrupted by the delivery of a signal(Not supported).
[EINVAL]
  The rqtp argument specified a nanosecond value less than zero or greater than or equal to 1000 million.
[ENOSYS]
  The nanosleep system call is not supported by this implementation.

See also

sleep

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top