LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 04-17-2002, 11:09 PM   #1
Rex_chaos
Member
 
Registered: Aug 2001
Location: GD, GZ, China
Posts: 240

Rep: Reputation: 30
Shell problem


I have written the following shell. First, the shell execute a program (client) which will return a exitcode. Then we have to check if the exitcode is 0. If so, reboot the computer.
The problem is that client is time-consuming program. So I want to let it run at background(./client &). However, I found the shell didn't wait the returned exitcode and jump to if statment soon.

# Run as root, of course
EXIT_CODE=0
./client

if [ $? -ne $EXIT_CODE ]
then
echo "Shell is terminated!"
exit -1
else
shutdown -r now
fi
 
Old 04-17-2002, 11:29 PM   #2
zmedico
Member
 
Registered: Feb 2002
Location: Mission Viejo, California, USA
Distribution: Gentoo
Posts: 707

Rep: Reputation: 30
It makes no sense to me to fork a new thread (&) if you want to wait for the exit code. Maybe you can run your script, which includes the client followed by the part that checks for the exit code, in a single background thread.
 
Old 04-19-2002, 02:13 AM   #3
xanthium
Member
 
Registered: Apr 2001
Location: Bombay ( INDIA )
Distribution: RedHat 7.x
Posts: 218

Rep: Reputation: 30
Did u try waiting ?

Hi Rex ,

After the (./client &) command did u try the wait command ?
it waits for the completion of the previous thread and so by using the $? shell metacharacter will be 0 if the the last background process ( in this case ur client&) was success.

i hope this is what u wanted ?

Regards,
Xanthium
 
Old 04-19-2002, 02:41 AM   #4
Rex_chaos
Member
 
Registered: Aug 2001
Location: GD, GZ, China
Posts: 240

Original Poster
Rep: Reputation: 30
Thanks. It works.
 
  


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
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
shell problem? ummmm.... Slackware 11 04-07-2005 07:35 PM
Help. Shell problem. miguel67 AIX 1 06-22-2004 01:05 PM
problem with shell artistik Linux - General 5 09-27-2003 01:59 PM
shell problem vivek10 Linux - General 2 01-16-2003 09:36 AM

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

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