Thread: sleep in milliseconds.

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    3

    sleep in milliseconds.

    Hi,
    Iam working on a project in LINUX and i require my program to go into sleep for 100ms or 200ms but sleep() takes only seconds as argumuments. Is there a way?? If there are no inbulit functions is there a way to count in milliseconds??Plz help.
    Also can u tell me wat C functions are used in writing data to the USB ports of linux machines?? Thx in advance.

    Sam.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well for sleep, you could try nanosleep()
    But beware that all sleep functions are a minimum sleep time, not an absolute sleep time.

    As for USB, perhaps here
    http://www.lvr.com/usb.htm
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    #define WORLD "sad place" LinuxCoder's Avatar
    Join Date
    Mar 2006
    Location
    Portugal
    Posts
    89
    check the manpage for select() which is used a lot for sockets. it reads:
    Some code calls select() with all three sets empty, n zero, and a non-null timeout as a fairly portable way to sleep with subsecond precision.
    So i guess this might be one way to achieve what you're looking for.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    8
    Besides nanosleep and select there is also usleep().

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sleep in milliseconds.
    By nethunter in forum C Programming
    Replies: 2
    Last Post: 04-10-2006, 02:25 PM
  2. Sleep works with just one thread, but not 2
    By finkus in forum C++ Programming
    Replies: 5
    Last Post: 12-01-2005, 09:17 PM
  3. Problem with Sleep() #$@^#$%^
    By intruder in forum C++ Programming
    Replies: 8
    Last Post: 10-11-2004, 06:46 AM
  4. why do we require sleep?
    By jinx in forum A Brief History of Cprogramming.com
    Replies: 43
    Last Post: 07-14-2004, 08:21 AM
  5. Sleep is overrated...
    By Polymorphic OOP in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-24-2003, 12:40 PM