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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:27:54+00:00 2026-05-29T09:27:54+00:00

I have this: puts pids pids.each do |pid| puts Running on pid #{pid} begin

  • 0

I have this:

puts pids
pids.each do |pid|
    puts "Running on pid #{pid}"
    begin
        Process::kill(0, pid)
        puts "Pid #{pid} still alive"
    rescue Errno::ESRCH
        puts "Pid #{pid} now dead!!!!"
        pids.delete(pid)
        running_jobs -= 1
        puts "Remaining jobs: #{running_jobs}"
    end
end

which outputs this:

25555
25579
25616
Running on pid 25555
Pid 25555 now dead!!!!
Remaining jobs: 2
Running on pid 25616
Pid 25616 now dead!!!!
Remaining jobs: 1    

As you can see, the loop is never executed on the middle element. Can anyone tell me why that happens that way? I need to really loop over every item and handle it accordingly.

  • 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-05-29T09:27:55+00:00Added an answer on May 29, 2026 at 9:27 am

    You are mutating the array as you iterate over it with pids.delete(pid) So you are on 25555 at index 0, then you delete it, causing the array to look like [25579, 25616]. Then you iterate, now you are at index 1, which is 25616. If you simply remove the delete, you will no longer be mutating the array and the iteration will work as expected.

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

Sidebar

Related Questions

Let's say I have this each loop in Ruby. @list.each { |i| puts i
I have this code if filename begin if filename == '-' ARGF.each{|url| begin check(url)
I have a textbox where a user puts a string like this: hello world!
I have this function that puts some data with Ajax call in a php
I have a newbie question! I want to do something like this: puts Example.new([a,b,c])
I have this code, which uses ob_start php function. Which basically puts the echoed
I have this piece of code: begin complete_results = Timeout.timeout(4) do results = platform.search(artist,
Have an ajax call to updateUser which does this: puts session[:user_id] user = User.find(params[:user_id])
I have this content: <div class=CodeRay> <div class=code><pre>puts <span style=background-color:#fff0f0;color:#D20><span style=color:#710>&quot;</span><span style=>Hello, world!</span><span style=color:#710>&quot;</span></span></pre></div>
I have this javascript, jquery function, (below) It gets the text inside each table

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.