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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:29:10+00:00 2026-05-10T21:29:10+00:00

EDIT: I’ve tagged this C in a hope to get more response. It’s more

  • 0

EDIT: I’ve tagged this C in a hope to get more response. It’s more the theory I’m interested in than a specific language implementation. So if you’re a C coder please treat the following PHP as pseudo-code and feel free to respond with an answer written in C.

I am trying to speed up a PHP CLI script by having it execute its tasks in parallel instead of serial. The tasks are completely independent of each other so it doesn’t matter which order they start/finish in.

Here’s the original script (note all these examples are stripped-back for clarity):

<?php  $items = range(0, 100);  function do_stuff_with($item) { echo '$item\n'; }  foreach ($items as $item) {     do_stuff_with($item); } 

I’ve managed to make it work on the $items in parallel with pcntl_fork() as shown below:

<?php  ini_set('max_execution_time', 0);  ini_set('max_input_time', 0);  set_time_limit(0);  $items = range(0, 100);  function do_stuff_with($item) { echo '$item\n'; }  $pids = array(); foreach ($items as $item) {     $pid = pcntl_fork();     if ($pid == -1) {         die('couldn't fork()');     } elseif ($pid > 0) {         // parent         $pids[] = $pid;     } else {         // child         do_stuff_with($item);         exit(0);     }    }  foreach ($pids as $pid) {     pcntl_waitpid($pid, $status); } 

Now I want to extend this so there’s a maximum of, say, 10 children active at once. What’s the best way of handling this? I’ve tried a few things but haven’t had much luck.

  • 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. 2026-05-10T21:29:11+00:00Added an answer on May 10, 2026 at 9:29 pm

    There is no syscall to get a list of child pids, but ps can do it for you.

    --ppid switch will list all children for you process so you just need to count number of lines outputted by ps.

    Alternatively you can maintain your own counter that you will increment on fork() and decrement on SIGCHLD signal, assuming ppid stays unchanged for fork’ed processed.

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

Sidebar

Related Questions

EDIT: This question is more about language engineering than C++ itself. I used C++
EDIT: This was formerly more explicitly titled: - Best solution to stop Kontiki's KHOST.EXE
Edit: This question was written in 2008, which was like 3 internet ages ago.
Edit: This was accidentally posted twice. Original: VB.NET Importing Classes I've seen some code
Edit: I have solved this by myself. See my answer below I have set
EDIT: upgraded this question to MVC 2.0 With asp.net MVC 2.0 is there an
Edit: Just wanted to make the question I have more clear. I pretty much
Edit: This is technically a 2 part question. I've chosen the best answer that
EDIT: had to retag this, because, it's rather a Sweave / R question since
EDIT: This is with Rails 2.3.5 For some reason, when I try to associate

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.