An overall function as a restart... | Unix Linux Forums | UNIX for Advanced & Expert Users

  Go Back    


UNIX for Advanced & Expert Users Expert-to-Expert. Learn advanced UNIX, UNIX commands, Linux, Operating Systems, System Administration, Programming, Shell, Shell Scripts, Solaris, Linux, HP-UX, AIX, OS X, BSD.

An overall function as a restart...

UNIX for Advanced & Expert Users


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-13-2013
wisecracker's Avatar
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 23 November 2014, 2:39 PM EST
Location: Loughborough
Posts: 663
Thanks: 137
Thanked 140 Times in 117 Posts
An overall function as a restart...

This is going to rasie a few eyebrows...

I have been thinking of running the WHOLE of the AudioScope project inside a function which I will call "restart()". A kind of wrapper function...

This is so that should there be anything that the user has set be wrong then a _cold_ start could be initialised again including deleting some Scope files if required...

I DO know that too many, (a lot of), recusions of this WILL cause a "segmenatation fault".

I was going to limit to say 5 restarts per session then any more and the program will stop.

The code like this:-

Code:
restart()
{
        ALL of the current and future scope code in here.
        Also restart can only be accessed from Command mode like...
        <pseudo_code>RESET calls restart()
}
restart

Alterntively if any of you know of any other way, like "GOTO" for example, then any input would be appreciated...
What are the opinions from you pro's.
I, as an amateur, would this sort of thing frowned upon?
Also, if, using this command a few times and then shutting down the program, AND, closing the terminal, can I guarantee the terminal closure will return all memory back to the pool?

I know I am asking some bizarre questions here but Google is not particularly my friend.
The Scope is now getting complex and making it _bullet_ proof is getting increasingly more difficult.

Thanks in advance...
Sponsored Links
    #2  
Old 07-13-2013
Don Cragun's Avatar
Don Cragun Don Cragun is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 27 November 2014, 5:59 PM EST
Location: San Jose, CA, USA
Posts: 5,105
Thanks: 196
Thanked 1,707 Times in 1,450 Posts
If we assume that you have a shell script (AudioScope) and that you invoke it with a command line like:

Code:
AudioScope arg1 ... argn

and after running for a while it decides it needs to restart itself. One way to do that is to issue the command:

Code:
exec AudioScope "$@"

This will overlay the current shell script with a new invocation of the script without changing its process ID (i.e., $$ will not change). If the script has opened files and not closed them, they will remain open (so you'll need to close any files that aren't needed when you restart before calling exec). Exported variables will have the values they had before calling exec; local variables will disappear. If some of your options or operands have been processed and are not wanted in the restart, they can be shift'ed off before calling exec; but if you processed options using something like getopts and shifted them off, you'll need to be sure to add the needed options for the restart into the list of arguments given to the exec command. Note also that any buffered data in files that do remain open may be lost in by exec.

But, you can do this all day without overflowing your stack.
The Following User Says Thank You to Don Cragun For This Useful Post:
wisecracker (07-13-2013)
Sponsored Links
    #3  
Old 07-13-2013
wisecracker's Avatar
wisecracker wisecracker is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 23 November 2014, 2:39 PM EST
Location: Loughborough
Posts: 663
Thanks: 137
Thanked 140 Times in 117 Posts
Hi Don Cragun...

Many thanks, your knowledge, and that of a few others on here too, astounds me.

Where would I be without you guys... ;o)

I will try that out as RESET command.
(These things are logged down now, in my aging grey matter.)

Look out for it soon... ;oD
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to step in one function after the function be executed in gdb? 915086731 Programming 4 10-31-2011 05:22 AM
SHELL SCRIPT Function Calling Another Function Please Help... omkar.sonawane Shell Programming and Scripting 2 04-13-2010 11:20 AM
Return a value from called function to the calling function mvictorvijayan Shell Programming and Scripting 1 09-14-2009 05:19 AM
Passing global variable to a function which is called by another function sars Shell Programming and Scripting 4 06-30-2008 12:39 PM
Postfix Restart kumarrana UNIX for Dummies Questions & Answers 4 02-16-2008 03:22 PM



All times are GMT -4. The time now is 07:02 PM.