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 8597037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:49:21+00:00 2026-06-12T00:49:21+00:00

I am running into the following problem on the latest version of OS X

  • 0

I am running into the following problem on the latest version of OS X 10.8.2, with latest Xcode 4.5.

Take the following simple piece of code:

#include <iostream>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main(int argc, const char * argv[])
{
    pid_t pid = fork();

    if (0 == pid)
    {
        std::cout << "Child process!\n";

        exit(0);
    }
    else if (-1 == pid)
    {
        std::cout << "Error forking.\n";
    }
    else
    {
        std::cout << "In parent, created pid " << pid << ".\n";

        sleep(100000);      // Sleep a long time - GDB/LLDB ignores the first sleep statement
        sleep(3);           // Sleep 3 more seconds - GDB/LLDB doesn't ignore the second sleep statement

        std::cout << "Done in parent!\n";
    }

    return 0;
}

Compile it using clang++ foo.cpp -o foo or g++ foo.cpp -o foo and run it using ./foo, it takes a long time to run, as expected.

Now do either lldb ./foo or gdb ./foo, then run and notice it completes in 3 seconds. Whenever either debugger is used, the first sleep statement is seemingly ignored.

Since Xcode uses lldb by default when running a project, pasting the above code into a blank Xcode project and doing Product->Run will have similar results.

I’ve tried the same experiment on a Linux machine with gdb 7.2, and the problem does not occur there.

Is this a bug in an older version of gdb that Apple uses (gdb 6.3.50-20050815 (Apple version gdb-1822) ), or is it something else? Perhaps just my computer is messed up, if it doesn’t happen to other OS X users?

  • 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-12T00:49:22+00:00Added an answer on June 12, 2026 at 12:49 am

    although many people do not use it, sleep actually has a return value.

    man 3 sleep:

    RETURN VALUES

    If the sleep() function returns because the requested time has elapsed,
    the value returned will be zero.  If the sleep() function returns due
    to the delivery of a signal, the value returned will be the unslept amount
    (the requested time minus the time actually slept) in seconds.
    

    sure enough, the expected value is returned considering the observed behavior.

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

Sidebar

Related Questions

I'm running into a problem with the following Python 3.2.2 code. The code is
I keep running into the following problem: (System.Console.ReadLine ()).Split [|'('; ')'|] |> Array.filter (fun
I'm running into issues with the following code: var setupSearch = { searchSuggest: function(field)
Trying my hand at Linux assembly and I'm running into the following problem. I'm
I am running into the following problem with gzip.exe, be it from UnxUtils or
I'm running into the following problem when setting up a whitelist for PHP: I've
I'm learning XML and I'm running into the following problem: I have an attribute
While doing a school project I've been running into the following problem: After feeding
I'm working to DRY some code up and I'm running into the following situation.
I am running into the following problem, I am passing an array of string

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.