LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
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
 
LinkBack Search this Thread
Old 02-01-2013, 03:00 AM   #1
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,007

Rep: Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003
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, 03:30 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,460

Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
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, 03:34 AM   #3
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,007

Original Poster
Rep: Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003Reputation: 1003
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, 06:21 AM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 1,460

Rep: Reputation: 445Reputation: 445Reputation: 445Reputation: 445Reputation: 445
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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to use exec in shell script sagar.gunjal Programming 16 12-19-2011 11:10 PM
Script question with find -exec linuxbird Linux - Newbie 12 05-15-2011 03:21 AM
Using exec in a shell script opus-outlaw Linux - Desktop 1 01-19-2008 11:47 AM
CGI works from SSI exec, but not from include. SkipHuffman Linux - Software 2 08-25-2005 10:15 PM
SSI works from #exec, but not from #include. SkipHuffman Linux - General 4 08-25-2005 07:16 AM


All times are GMT -5. The time now is 02:57 AM.

Main Menu
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