LinuxQuestions.org
Visit Jeremy's Blog.
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 02-01-2013, 04:00 AM   #1
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,139

Rep: Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363
how exec <script> works?


I have the following shell script (starter):
Code:
#!/bin/sh -f

MYDIR="some path to the real script"

exec ${MYDIR}/job "$@"
also I have another perl script (job):
Code:
eval '(exit $?0)' && eval 'exec ${PERL_BIN} -wS ${PERL_LIBS} $0 ${1+"$@"}' && eval 'exec ${PERL_BIN} -wS ${PERL_LIBS} $0 $argv:q'
   if 0;

#perl code
all these things are started from a tcsh shell by executing the starter script (that is executable). PERL_BIN and PERL_LIBS are set properly.

My questions:
how exec <script> is executed, so what will happen in the starter script (how many processes were forked, which?) and how optimal is it?
(I think a simple exec $PERL_BIN -w $MYDIR/job would be more efficient - is it true?)

Just a comment: I found this structure somewhere and I want to understand it
 
Old 02-01-2013, 04:30 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,923

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
The first one I sort of understand: the shell replaces itself with another program (see execve(2), execv(3)); passes its parameter to the new program.
 
Old 02-01-2013, 04:34 AM   #3
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,139

Original Poster
Rep: Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363Reputation: 1363
Yes, that is the problem. The new program is not a binary executable but a text file, therefore cannot be execed.
 
Old 02-01-2013, 07:21 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,923

Rep: Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524Reputation: 524
It has to have the x (executable) bit set to be executed; the lack of the she-bang will result in executing it with the default shell (/bin/sh).
 
  


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 use exec in shell script sagar.gunjal Programming 16 12-20-2011 12:10 AM
Script question with find -exec linuxbird Linux - Newbie 12 05-15-2011 04:21 AM
Using exec in a shell script opus-outlaw Linux - Desktop 1 01-19-2008 12:47 PM
CGI works from SSI exec, but not from include. SkipHuffman Linux - Software 2 08-25-2005 11:15 PM
SSI works from #exec, but not from #include. SkipHuffman Linux - General 4 08-25-2005 08:16 AM


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