LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 03: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, 04:25 PM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
Code:
myprogram &
MYPID=$!
while [ -f /proc/$MYPID ]
do
  ...
done
 
Old 02-17-2010, 06: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, 03:22 AM   #4
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
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, 05:01 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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, 05:39 AM   #6
Valery Reznic
ELF Statifier author
 
Registered: Oct 2007
Posts: 675

Rep: Reputation: 136Reputation: 136
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, 12:12 PM   #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


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


All times are GMT -5. The time now is 06:32 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration