The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to include RETURN KEY with Background process "&" in Shell Script racbern Shell Programming and Scripting 1 03-11-2008 04:30 AM
Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" iBot UNIX and Linux RSS News 0 01-04-2008 12:00 PM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 10:52 PM
No utpmx entry: you must exec "login" from lowest level "shell" peterpan UNIX for Dummies Questions & Answers 0 01-18-2006 01:15 AM
My "Bread and Butter" Process Keep Alive Perl Script.... Neo Tips and Tutorials 0 01-08-2005 02:17 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1  
Old 06-27-2008
Registered User
 

Join Date: Apr 2008
Posts: 56
execv lauches a process using "/bin/sh -c"

Inside the C program, when execv(cPath, argv) is called, it launches new process image using "/bin/sh -c" option even if it is getting launched from C-shell. Is there a way to make execv to use "/bin/csh " or "/bin/sh"(without -c option)..
Reply With Quote
Forum Sponsor
  #2  
Old 06-27-2008
Registered User
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 250
You are confused. system() performs the shell driven execution. man execve (which is the core function for the C exec() functions) is what you need to read. exec will only execute the shell when the first line contains the bang #!$(shell here) token. Thus you can exec any shell script in any shell using the exec functions.
Reply With Quote
  #3  
Old 06-27-2008
Registered User
 

Join Date: Jul 2005
Posts: 10
Quote:
Originally Posted by shafi2all View Post
Inside the C program, when execv(cPath, argv) is called, it launches new process image using "/bin/sh -c" option even if it is getting launched from C-shell. Is there a way to make execv to use "/bin/csh " or "/bin/sh"(without -c option)..
You are confusing the system function with the execv function, don't you? I mean, the execv function will replace the current process image with a new one. According to the execv man page (extracted from a Solaris box):


Quote:
Each of the functions in the exec family replaces the
current process image with a new process image. The new
image is constructed from a regular, executable file called
the new process image file. This file is either an execut-
able object file or a file of data for an interpreter. There
is no return from a successful call to one of these func-
tions because the calling process image is overlaid by the
new process image.

An interpreter file begins with a line of the form

#! pathname [arg]


where pathname is the path of the interpreter, and arg is an
optional argument. When an interpreter file is executed, the
system invokes the specified interpreter. The pathname
specified in the interpreter file is passed as arg0 to the
interpreter. If arg was specified in the interpreter file,
it is passed as arg1 to the interpreter. The remaining argu-
ments to the interpreter are arg0 through argn of the origi-
nally exec'd file. The interpreter named by pathname must
not be an interpreter file.
while the system function will execute the command string by calling the system's shell:

Quote:
system() executes a command specified in string by calling /bin/sh -c
string, and returns after the command has been completed. During exe-
cution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT
will be ignored.
Reply With Quote
  #4  
Old 06-29-2008
Registered User
 

Join Date: Apr 2008
Posts: 56
For my case of execv(cPath, argv),

Current process image, argv[0] is "/finder/95s/ed/bin/or_run_report"
and new process image, cPath is "/users/sch83995/test/sbin/or_run_report".

Please look at the below output where current process image is not getting terminated..and new process image is launched.


Reva% ps -ef | grep report
shafi 26624 26078 0 11:42:37 pts/43 0:00 grep report
shafi 26586 1 0 11:42:07 pts/43 0:00 /bin/csh -f /finder/95s/ed/sbin/reports_run_launcher SPIDER
shafi 25413 24346 0 11:10:41 pts/32 0:00 vi or_run_report.csh
shafi 26597 26589 0 11:42:18 pts/43 0:00 /bin/sh -c /finder/95s/ed/bin/or_run_report 'INSTALL/install@fnd9i' SPIDER /use
shafi 26598 26597 0 11:42:18 pts/43 0:00 /bin/csh -f /users/sch83995/test/sbin/or_run_report SPIDER /users/sch83995/12
Reva%
Reva%
Reply With Quote
  #5  
Old 06-30-2008
Registered User
 

Join Date: Oct 2007
Location: USA
Posts: 567
Which shell is chosen to execute a script depends only on the format of the shebang line in your script. It has nothing to do with the shell that you are currently interacting with. If your script does not contain the shebang line and you want to pick the shell for your script's execution use the execl() system call.
Reply With Quote
  #6  
Old 07-06-2008
Registered User
 

Join Date: Apr 2008
Posts: 56
I used "/bin/ksh -c" instead "/bin/sh -c" .. It resolved my problem..I hope this will not affect ? I am using Korn-Shell to execute the binary executable(C-programme) ?
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
solaris

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:11 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0