execv lauches a process using "/bin/sh -c"


 
Thread Tools Search this Thread
Top Forums Programming execv lauches a process using "/bin/sh -c"
# 1  
Old 06-27-2008
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)..
# 2  
Old 06-27-2008
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.
# 3  
Old 06-27-2008
Quote:
Originally Posted by shafi2all
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.
# 4  
Old 06-30-2008
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%
# 5  
Old 06-30-2008
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.
# 6  
Old 07-07-2008
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) ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

Mindboggling difference between using "tee" and "/usr/bin/tee" in bash

I'm on Ubuntu 14.04 and I manually updated my coreutils so that "tee" is now on version 8.27 I was running a script using bash where there is some write to pipe error at some point causing the tee command to exit abruptly while the script continues to run. The newer version of tee seems to prevent... (2 Replies)
Discussion started by: stompadon
2 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

If cmd in in "A/user/bin A/bin A/user/sbin" but not "B/user/bin B/bin B/user/sbin" directory print t

there are two directories A and B if cmd in in "A/user/bin A/bin A/user/sbin" but not "B/user/bin B/bin B/user/sbin" directory print them (1 Reply)
Discussion started by: yanglei_fage
1 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. UNIX for Dummies Questions & Answers

Difference between "/bin/bash" & "/bin/sh"

what if the difference between #!/bin/sh and #!/bin/bash I wrote a script with the second heading now when i change my heading to the first one ...the script is not executing well....im not getting the required output....any solution to this problem...or do i have to start the... (3 Replies)
Discussion started by: xerox
3 Replies

7. Shell Programming and Scripting

difference between "#! /bin/sh" and "#! /bin/sh"

In shell Programming, we know it should begin with "#! /bin/sh", it means use /bin/sh to interpreter the following command in the shell script. But today I saw "#! /bin/sh -", it saied using "-" follow "#! /bin/sh " can avoid spoofing attack. Anyone could explain that for me? What is... (1 Reply)
Discussion started by: cqlouis
1 Replies

8. Infrastructure Monitoring

HPUX net-SNMP interpreter "/bin/perl" not found

I am trying to install net-snmp on an HPUX box. I am getting the fallowing error message when I try to run the snmpconf file. I installed the fallowing version of net-snmp net-snmp-5.0.10.2-HP-UX_B.11.11_9000_800.tar and my HPUX box is version HP-UX commnms B.11.11 U 9000/800... (2 Replies)
Discussion started by: krisarmstrong
2 Replies

9. Red Hat

"service" , "process" and " daemon" ?

Friends , Anybody plz tell me what is the basic difference between "service" , "process" and " daemon" ? Waiting for kind reply .. .. (1 Reply)
Discussion started by: shipon_97
1 Replies

10. UNIX for Dummies Questions & Answers

#!/bin/sh script fails at StringA | tr "[x]" "[y]"

I need to take a string (stringA) check it for spaces and replace any spaces found with an equal (=) sign. This is not working. There are spaces between each component: $StringA | tr "" "" The error returned is: test: Specify a parameter with this command Can you help? (3 Replies)
Discussion started by: by_tg
3 Replies
Login or Register to Ask a Question