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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T05:30:59+00:00 2026-05-11T05:30:59+00:00

Perl’s system() starts a process, but breaks the parent/child relationship? test.pl: use POSIX; system(./test.sh

  • 0

Perl’s system() starts a process, but breaks the parent/child relationship?

test.pl:

use POSIX;  system('./test.sh &');  my $pid = `ps -C test.sh -o pid=`;  print 'pid: -$pid-\n';  waitpid($pid, 0); 

test.sh:

while true do     sleep 1 done 

When I run test.pl, it finds and prints a correct pid of test.sh. But waitpid() returns -1 and test.pl exits. After test.pl exist, test.sh is still running.

It looks like test.sh is not a child of test.pl, which breaks waitpid(). Why does this happen and how to make system() behave? Is that because Perl clears children automatically? If yes, how can I solve a general task of waiting on a child explicitly?

Update:

answers below suggest using fork/exec. The initial problem is this:

  1. from a Perl script, run a command-line utility that starts a service. The utility exits but the service stays.

  2. after some time, find that service’s pid and wait on it.

fork/exec doesn’t solve this, although it clears up the question.

  • 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-11T05:31:00+00:00Added an answer on May 11, 2026 at 5:31 am

    The test.sh process is not your child process. The system() forked a shell (which is your child), that shell forked a child that ran the test.sh program. The shell that was your child exited.

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

Sidebar

Related Questions

In perl debugger I can use DB::get_fork_TTY() to debug both parent and child process
Perl question for you: #!/usr/bin/perl use File::Find; #Find files find(\&wanted, $dir); sub wanted {
Perl has OOP features, but they are somewhat rarely used. How do you create
Perl supports three ways (that I know of) of running external programs: system :
perl -e 'system (crontab1 -l);print $?' returns -1 as expected (program crontab1 doesn't exist)
Perl allows you to use the '..' operator to return a slice from an
Perl has long been my choice scripting language but I've run into a horrible
Perl newbie here. Can someone kindly show me how to use perl to extract
Perl (no modules loaded and -Tw & strict) I found much info on regex
perl -T Do you use it? Does it help you finding security holes in

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.