LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
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-26-2012, 10:04 PM   #1
johnifanx98
LQ Newbie
 
Registered: Jan 2008
Posts: 26

Rep: Reputation: 0
What is the basic idea of "exec" designed for?


As its help page says,

Code:
exec: exec [-cl] [-a name] file [redirection ...]
   Exec FILE, replacing this shell with the specified program.
This first sentence really thows me off...

Replace a shell with a program???

Last edited by johnifanx98; 02-26-2012 at 10:16 PM.
 
Old 02-26-2012, 10:30 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,576
Blog Entries: 31

Rep: Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195Reputation: 1195
The shell is a program. When it is loaded it runs in a process.

The running shell can run a program either
a) by loading the program into a new process
or
b) by loading the program into its own process, replacing itself.
 
1 members found this post helpful.
Old 02-26-2012, 10:35 PM   #3
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 373Reputation: 373Reputation: 373Reputation: 373
It may not seem like a useful task, but it is.

You are thinking of it from the perspective of an interactive shell--one where you type commands and wait for a response. But that's only part of the story. A shell is created whenever you spawn a shell script. Another copy of bash is created in memory and run. You do not interact with it, but it is there. That shell consumes system resources (RAM and processor time at a minimum).

At some point, the script's internal logic may conclude that only one specific program needs to run to finish whatever task it is meant to accomplish. Without using exec, the bash shell created for the shell script will sit, idle and unused (locking those computer resources) while the specific program runs to completion. Only when the specific program completes will the shell that spawned it finally end and free the resources used by that shell.

If the shell concludes that it does not need to do anything else other than the one, specific program--using exec "frees" the resources used by the shell in the sense that the specific program "takes over." That specific program will require resources of its own, but the net effect is that the shell no longer exists, and those resources are no longer consumed.
 
1 members found this post helpful.
Old 02-27-2012, 07:19 AM   #4
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
exec command treats its arguments as the specification of one or more subprocesses to execute. The arguments take the form of a standard shell pipeline where each arg becomes one word of a command, and each distinct command becomes a subprocess.

If the initial arguments to exec start with - then they are treated as command-line switches and are not part of the pipeline specification.
 
1 members found this post helpful.
  


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
[SOLVED] "Insert" & "Delete" key returns "~" in a terminal. sharky Linux - General 15 04-26-2011 09:36 AM
No UTMPX entry, You must EXEC "login" for the lowest "shell" ooihc Solaris / OpenSolaris 7 03-12-2007 03:09 PM
Can't exec "firefox 1.5", "prompts glibc detected" SPo2 Linux - General 1 06-05-2006 12:02 AM
Can double-click the shell script and choose "Run in Terminal" in Redhat? edwardsiow Programming 2 05-22-2006 09:56 PM

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

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