LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 04-30-2011, 06:41 PM   #1
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Rep: Reputation: 16
get pid of launched bash file


Hi,

I've created a bash file that calls another bash. And I would like to get the pid from the second file launched, to wait for the file to ends. The second bash file launches processes in background. How can I get the PID from the second bash file?

Here's my code:

Code:
#!/bin/bash                                                                     

echo "FIRST"
./second.sh
PID=$(echo $!)
wait $PID
echo "CONTINUUING FIRST"
 
Old 04-30-2011, 07:25 PM   #2
DarkVenger
Member
 
Registered: Mar 2004
Location: VCO
Distribution: Arch
Posts: 43

Rep: Reputation: 26
Maybe using the $$ built in variable?

Just my 2 cents...
 
Old 05-01-2011, 04:14 PM   #3
xeon123
Member
 
Registered: Sep 2006
Posts: 374

Original Poster
Rep: Reputation: 16
But how can I get the PID from the launched second.sh in the first.sh script?
 
Old 05-01-2011, 05:46 PM   #4
DarkVenger
Member
 
Registered: Mar 2004
Location: VCO
Distribution: Arch
Posts: 43

Rep: Reputation: 26
Just use pgrep to get the pid you want
Example PID=$(pgrep second.sh)
 
  


Reply



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
(20014)Internal error: Error retrieving pid file /var/run/apache2.pid yuri16 Linux - Server 0 07-28-2009 03:11 AM
(bind) named: couldn't open pid file '/var/run/named/named.pid' - any help? samengr Linux - Server 6 04-01-2009 06:22 AM
reading pid from pid file in C language shifter Programming 1 05-14-2008 10:49 AM
get pid in bash merlin23 Linux - Newbie 3 12-07-2004 08:38 AM
ERROR: Couldn't write pid to pid file lawrencegoodman Linux - Newbie 2 02-13-2004 08:05 PM

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

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