Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9132143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:15:43+00:00 2026-06-17T08:15:43+00:00

My program gets stuck in the simple call usleep(1.); . How can that be?

  • 0

My program gets stuck in the simple call usleep(1.);. How can that be? What should I look out for?

Edit:

To make things even more confusing, it only gets stuck if I call rand() before:

rand();
usleep(1.);

Both calls individually are just fine.

Edit 2:

Here is a minimal example that works:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char* argv[]) {
        printf("Calling rand() and then usleep(1) on pid %d \n",getpid());
        rand();
        usleep(1);
        printf("Finished.\n");
        return 0;
}

This one also works:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char* argv[]) {
        printf("Calling usleep(1.) on pid %d \n",getpid());
        usleep(1.);
        printf("Finished.\n");
        return 0;
}

However, this one does not:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char* argv[]) {
        printf("Calling rand() and then usleep(1.) on pid %d \n",getpid());
        rand();
        usleep(1.);
        printf("Finished.\n");
        return 0;
}

I compile these with gcc version 4.4.6 using the command gcc -std=c99 main.c. Is the option -std=c99 the problem? But I still don’t understand what’s going on here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:15:44+00:00Added an answer on June 17, 2026 at 8:15 am

    You’re calling usleep() with a double value, while it’s specified to take an unsigned integer of type useconds_t with limited range. See the manual page.

    Perhaps the conversion fails, on your platform. Try removing the period, and just call it with 1.

    Don’t introduce casts, it’s best to not mention the useconds_t type.

    Also, note that this function is obsolete, new POSIX code should use nanosleep() instead.

    UPDATE By the way, the manual page linked above also seems to imply that you should #define the proper symbols as listed before #include <unistd.h>, to get this function. You should try that, if you’re not getting the prototype the argument will not be automatically converted from double. The (ignored) return value from rand() might also be in some register or on the stack, causing things to further change in that case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am really stuck here, just trying to make a simple C program
My client program gets stuck on NetworkStream.Read even though the server is reporting it's
I have a program that gets a JSON from the server using getJSON and
I have a program that gets the FOV angle of the device's rear-facing camera,
I've wrote a program that gets a string, and then calculate a total value
I am supposed to write a program that gets some PNG images from the
I am writing a small program that gets activated when sms is received.We need
I am working on a small basic GUI program that gets the files from
I am completely stuck. This is my incomplete program. The program gets stuck at
Hey guys I'm trying to write a simple socket program that basically send like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.