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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:42:26+00:00 2026-06-01T22:42:26+00:00

I have a relatively simple pthread program on Linux. For this purpose, I’ve stripped

  • 0

I have a relatively simple pthread program on Linux. For this purpose, I’ve stripped it to a small piece, posted at the end.

All the man pages for wait(2) say that wait() will block unless WNOHANG is used (which is not even possible to specify for wait()). Looking at truss output, it’s just a non-stop repetition of:

5460  wait4(-1, 0x7f8ee479fea8, 0, NULL) = -1 ECHILD (No child processes)

again, looking at man page of wait4(2), it says that the return results are same as for waitpid(), and waitpid should block unless there is WNOHANG, and truss shows that the call was made with options being 0.

For reference, this is:

  • 2.6.32-300.3.1.el6uek.x86_64
  • glibc-2.12-1.47.el6_2.9.x86_64
  • gcc-4.4.6-3.el6.x86_64
  • compiled with: gcc -pthread -lpthread -o ptw -Wall ptw.c

—

#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>



static pthread_mutex_t _lock = PTHREAD_MUTEX_INITIALIZER;
static pthread_cond_t  _sem = PTHREAD_COND_INITIALIZER;

static void* waiter(void*);

int main(int argc, char ** argv) {

    pthread_t thr;

    if (pthread_create(&thr, 0, waiter, 0)) {
        perror("pthread_create");
        return 1;
    }

    pthread_mutex_lock(&_lock);
    pthread_cond_wait(&_sem, &_lock);

    return 0;

}

void* waiter(void* arg) {

    while (1) {
        int status;
        int p = wait(&status);
        if (p<0) {
            perror("wait");
            // fprintf(stderr, "wait returned without exited child\n");
        }
    }

    return 0;

}
  • 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-01T22:42:27+00:00Added an answer on June 1, 2026 at 10:42 pm

    wait() will also return immediately if there is no child process to wait for, with value -1 and errno set to ECHILD (which is what your strace is showing you). What were you expecting it to do in the case where no child processes exist?

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

Sidebar

Related Questions

I have this relatively simple regex for usernames // Enforce that username has to
I have a relatively simple program where I try establish Client Server connection and
I have a relatively simple program that currently uses 1 thread (main). The application
So I have this relatively simple query to pull a random row based on
I'm seeing this issue . I have a relatively simple ASP.NET page with a
I have a relatively simple abstract class. I've simplified it further for this question.
A relatively simple question. I have a datagridview, which all it does is displays
This should have been a relatively simple one but I must be making a
I have a relatively simple select statement in a VB6 program that I have
I have been working on a (relatively) simple tcp client/server chat program for my

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.