LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-07-2007, 05:06 PM   #1
kborgnis
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Rep: Reputation: 0
Bash child process in foreground while parent dies


Hello,

I'm writing a script that is meant to be run on a mounted CD. At the end of the script, I want to run another script which will be located on the local disk.

This secondary script will perform a few tasks in addition to ejecting the aforementioned CD, but will require user input. The problem I can't figure out is after the first script exits, control of the shell is given up and the second script fails because it is unable to read from STDIN.

How can I transfer control of the terminal to the second script?

Thanks,
kb

/media/cdrom/script-on-cd.sh
Code:
#!/bin/bash

echo "I'm on a CD"

/tmp/script-on-disk.sh &

/tmp/script-on-disk.sh
Code:
#!/bin/bash

echo "I'm on the local disk!"
sleep 10

eject

echo "Ejected!"
echo "More food please. Press enter when you're ready"
read CONTINUE

echo "Thanks!"
 
Old 11-07-2007, 05:39 PM   #2
kborgnis
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Red face

I feel like an idiot.

exec did just what I wanted. :-P

/media/cdrom/script-on-cd.sh
Code:
#!/bin/bash

echo "I'm on a CD"

exec /tmp/script-on-disk.sh
 
Old 11-08-2007, 12:10 PM   #3
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
You really don't even need exec in this case. Just forego the &. Or you could just use a symlink. Or you could replace exec in your solution with ".".
ta0kira
 
Old 11-09-2007, 07:50 AM   #4
kborgnis
LQ Newbie
 
Registered: Nov 2007
Posts: 3

Original Poster
Rep: Reputation: 0
Wouldn't the script located on the CD wait until the second script completed before it exited? Then wouldn't that prevent the CD from unmounting and ejecting?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TCL/expect - parent hangs when child dies Hewson Programming 1 03-27-2007 09:44 PM
child process usses same amount of ram as parent process socialjazz Programming 7 10-19-2006 06:48 PM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 02:19 PM
about parent and child process winwar Solaris / OpenSolaris 3 07-23-2003 07:07 AM
child and parent process error jdevanand Programming 1 04-29-2002 09:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration