LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 02-17-2010, 02:48 PM   #1
throughthegreens
Member
 
Registered: Feb 2010
Location: Asekhshinuv Sacramento,Ca
Distribution: Slackware 13.0
Posts: 35

Rep: Reputation: 16
break while [...] loop when a program finishes


I would like to start a program, then start a while loop that stops when the started program finishes, in bash. I thought I could run
Code:
 (program ; stat=1) & 
     while [ $stat -eq 0 ]; ... done
in a bash script
 
Old 02-17-2010, 03:25 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Code:
myprogram &
MYPID=$!
while [ -f /proc/$MYPID ]
do
  ...
done
 
Old 02-17-2010, 05:36 PM   #3
throughthegreens
Member
 
Registered: Feb 2010
Location: Asekhshinuv Sacramento,Ca
Distribution: Slackware 13.0
Posts: 35

Original Poster
Rep: Reputation: 16
thanks
 
Old 02-18-2010, 02:22 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by acid_kewpie View Post
Code:
myprogram &
MYPID=$!
while [ -f /proc/$MYPID ]
do
  ...
done
/proc/$MYPID is directory, so it should be '-d' instead of '-f'
Code:
while [ -d /proc/$MYPID ]
Another option is to use 'kill -0 $MYPID'
 
Old 02-18-2010, 04:01 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
Duh, actually I was wondering if my logic was even worse as it's procfs not a real filesystem, so presumably -f would never work even on files in there.
 
Old 02-18-2010, 04:39 AM   #6
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 676

Rep: Reputation: 137Reputation: 137
Quote:
Originally Posted by acid_kewpie View Post
Duh, actually I was wondering if my logic was even worse as it's procfs not a real filesystem, so presumably -f would never work even on files in there.
I tried and it's looks like -f and -d work as they should on procfs too.
 
Old 02-18-2010, 11:12 AM   #7
throughthegreens
Member
 
Registered: Feb 2010
Location: Asekhshinuv Sacramento,Ca
Distribution: Slackware 13.0
Posts: 35

Original Poster
Rep: Reputation: 16
i used -e
 
  


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
How to break if loop in Perl? Barca Programming 9 08-03-2011 01:15 PM
Break the order of calling functions in a program horacioemilio Programming 7 12-23-2007 10:40 AM
How do you automatically power off after a program finishes? cscott Linux - Software 7 03-14-2005 03:36 AM
Kdevelop splash screen finishes loading then program crashes BluePyre Linux - Software 1 08-25-2004 01:51 PM
break loop in C++ marek Programming 10 09-11-2003 10:59 AM

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

All times are GMT -5. The time now is 10:39 AM.

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