LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-18-2006, 10:28 PM   #1
idoneous
LQ Newbie
 
Registered: Jul 2006
Location: York, PA
Distribution: Linux Mint 14
Posts: 27

Rep: Reputation: 0
Bash Question: Need PID of sub script at launch


Hello all! I have been 16 years absent from computing. I have a bash script that launches another bash script. I need the parent script to find and assign the the process ID of the child script to a variable for later control. I can't for the life of me remember how to obtain it "scriptomatically". Any and all memory jogging suggestions would be much appreciated.
tiav from an old fart,
idoneous
 
Old 07-18-2006, 11:38 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

The following special parameter will give you just that:

$! Expands to the process ID of the most recently executed background (asynchronous) command.

Hope this helps.
 
Old 07-18-2006, 11:42 PM   #3
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
As an example:
Code:
#!/bin/bash

start_new_program.sh &
CHILD=$!
sleep 10

#kill child, it's had 10 seconds
kill $CHILD
 
Old 07-19-2006, 01:19 PM   #4
idoneous
LQ Newbie
 
Registered: Jul 2006
Location: York, PA
Distribution: Linux Mint 14
Posts: 27

Original Poster
Rep: Reputation: 0
Says Lucy to Schroeder: That's It!!

druuna and matir,
Thanks! That is exactly what I was looking for. Works like a charm.
 
Old 07-19-2006, 04:35 PM   #5
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I'm glad it works for you. Let us know if there's anything else we can do to help.
 
  


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
bash script, monitoring running PID? thebover Programming 4 08-26-2004 02:42 PM
Bash script question deiussum Programming 6 08-14-2004 11:43 AM
bash script question djgerbavore Linux - Newbie 3 07-08-2004 03:39 PM
small bash script to kill a PID flosch Linux - General 3 05-06-2004 09:28 PM
how to find the pid of a perl script from shell script toovato Linux - General 1 12-19-2003 06:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:04 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