Why does ksh exec() the last command in a shell script?

Solution Verified - Updated -

Issue

  • After running the last command in a script the parent process dies. In the following example child1.sh executes /bin/sleep.

  • The ps output shows the sleep, however the script that is calling the sleep (in this case child1.sh) doesn't show :

    [root@dhcp ~]# cat kshtest.sh 
    #!/usr/bin/ksh
    #
    echo "Starting Parent, DATE: `date`"
    echo "Parent PID:$$"
    echo "Executing child process: ./child1.sh &"
    ./child1.sh &
    echo "Child PID: $!"
    /bin/sleep 120
    echo "Parent Finished, DATE: `date`"
    
    [root@dhcp ~]# cat child1.sh 
    #!/usr/bin/ksh
    #
    /bin/sleep 200
    
    
    LINUX @Runtime:
    ---------------
    $ ./kshtest.sh
    Starting Parent, DATE: Mon Oct 25 16:54:00 CDT 2010
    Parent PID:11477
    Executing child process: ./child1.sh &
    Child PID: 11479
    
    PS capture:
    root  5478  5477  0 15:12 pts/2    00:00:00          -bash
    root 11477  5478  0 16:54 pts/2    00:00:00          /usr/bin/ksh ./kshtest.sh
    root 11479 11477  0 16:54 pts/2    00:00:00          /bin/sleep 200                    <----- There is no child1.sh process
    
  • This behaviour is not seen in other shells.

Environment

  • Red Hat Enterprise Linux 5.5
  • Ksh version 93t+

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.