Sponsored Content
Top Forums UNIX for Dummies Questions & Answers How to run two commands from a exec call in a c program Post 302366710 by pludi on Friday 30th of October 2009 06:28:44 AM
Old 10-30-2009
From the man page of exec(3):
Quote:
The exec() family of functions replaces the current process image with a new process image.
Means that as soon as the execv() is executed, the current process (your program) is completely replaced by the program you're starting. Any instructions left in the original program won't be executed.

If you want to just run a child process, use system(3)
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Exec. commands in python

How would i do if i'd want to execute a command in a python script or programme ? (1 Reply)
Discussion started by: J.P
1 Replies

2. UNIX for Dummies Questions & Answers

need to restrict program exec and running

I'm on Freebsd 4.5 stable, havin question of that kind: I need to restrict programs running, like BitchX for example, which can be dowlnoaded by logged on user, and i cant set permissions to all users to prevent that program from executing. And ipfw doesnt help me because of i need to allow that... (1 Reply)
Discussion started by: hachik
1 Replies

3. Programming

exec() system call

hi there, i was reading about the exec() function. and if i m not wrong, exec() kills your present process and starts a new process in its place. the process id remains the same. then it says if exec is successful the text data and stack are overlayed by new file! - i dont get this part "only... (2 Replies)
Discussion started by: a25khan
2 Replies

4. UNIX for Advanced & Expert Users

exec to call specific function in C prog

I would like to call a particular function in a C program using execl(). Is this possible using execl or anyother function ? Thanks (2 Replies)
Discussion started by: vpraveen84
2 Replies

5. Programming

How forbid use fork() in exec() program.

Hello World! I am writing code in C++ which have to launch another application X using exec(). I would like to set some limits on it using setrlimit etc... My problem is that i don't know how to forbid using fork() and strlimit by application X. How can i do it? (3 Replies)
Discussion started by: kzi
3 Replies

6. UNIX for Dummies Questions & Answers

How to run multiple piped commands in a find -exec statement?

I can't get this to work. Running a single command works fine: find . -name "*.dat" -exec wc -l '{}' \; gives me the file name and number of lines in each .dat file in the directory. But what if I want to pipe commands, e.g. to grep something and get the number of lines with that pattern... (3 Replies)
Discussion started by: DJR
3 Replies

7. Programming

[C] exec system call

Hi again ;) Now I want to make a program that will execute the programs with exec, asking the user if he wants the program to run in background or foreground. scanf("%c",&caracter); if (caracter=='y'){ printf("Has decidido ejecutarlo en background\n"); if((pid=fork())==0) {// fork para... (3 Replies)
Discussion started by: lamachejo
3 Replies

8. Shell Programming and Scripting

[Solved] Run multiple commands in invoked program

Hi, I have coded a program in Haskell using the compiler Hugs and the program requires multiple commands (with parameters) to be entered into it, it then outputs the result of its execution. I need to test a lot of different options (i.e. the parameters) so it would be obvious to automate the... (0 Replies)
Discussion started by: tz742
0 Replies

9. Shell Programming and Scripting

Run 2 exec commands

I have to create two instances of jBoss 5.1.0 GA. In order to do that I have to execute the following in start-jboss.sh: find . -exec /opt/novell/idm/jboss/bin/run.sh -Djboss.service.binding.set=ports-01 -c IDMProv -b 0.0.0.0 \; -exec /opt/novell/idm/jboss/bin/run.sh... (4 Replies)
Discussion started by: Joydeep Ghosh
4 Replies

10. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies
EXEC(3) 						     Linux Programmer's Manual							   EXEC(3)

NAME
execl, execlp, execle, execv, execvp - execute a file SYNOPSIS
#include <unistd.h> extern char **environ; int execl(const char *path, const char *arg, ...); int execlp(const char *file, const char *arg, ...); int execle(const char *path, const char *arg, ..., char * const envp[]); int execv(const char *path, char *const argv[]); int execvp(const char *file, char *const argv[]); DESCRIPTION
The exec() family of functions replaces the current process image with a new process image. The functions described in this manual page are front-ends for execve(2). (See the manual page for execve(2) for further details about the replacement of the current process image.) The initial argument for these functions is the pathname of a file which is to be executed. The const char *arg and subsequent ellipses in the execl(), execlp(), and execle() functions can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program. The first argument, by convention, should point to the filename associated with the file being executed. The list of arguments must be terminated by a NULL pointer, and, since these are variadic functions, this pointer must be cast (char *) NULL. The execv() and execvp() functions provide an array of pointers to null-terminated strings that represent the argument list available to the new program. The first argument, by convention, should point to the filename associated with the file being executed. The array of pointers must be terminated by a NULL pointer. The execle() function also specifies the environment of the executed process by following the NULL pointer that terminates the list of arguments in the argument list or the pointer to the argv array with an additional argument. This additional argument is an array of pointers to null-terminated strings and must be terminated by a NULL pointer. The other functions take the environment for the new process image from the external variable environ in the current process. Special semantics for execlp() and execvp() The functions execlp() and execvp() will duplicate the actions of the shell in searching for an executable file if the specified filename does not contain a slash (/) character. The search path is the path specified in the environment by the PATH variable. If this variable isn't specified, the default path ":/bin:/usr/bin" is used. In addition, certain errors are treated specially. If permission is denied for a file (the attempted execve(2) failed with the error EACCES), these functions will continue searching the rest of the search path. If no other file is found, however, they will return with errno set to EACCES. If the header of a file isn't recognized (the attempted execve(2) failed with the error ENOEXEC), these functions will execute the shell (/bin/sh) with the path of the file as its first argument. (If this attempt fails, no further searching is done.) RETURN VALUE
If any of the exec() functions returns, an error will have occurred. The return value is -1, and errno will be set to indicate the error. ERRORS
All of these functions may fail and set errno for any of the errors specified for the library function execve(2). CONFORMING TO
POSIX.1-2001. NOTES
On some other systems the default path (used when the environment does not contain the variable PATH) has the current working directory listed after /bin and /usr/bin, as an anti-Trojan-horse measure. Linux uses here the traditional "current directory first" default path. The behavior of execlp() and execvp() when errors occur while attempting to execute the file is historic practice, but has not tradition- ally been documented and is not specified by the POSIX standard. BSD (and possibly other systems) do an automatic sleep and retry if ETXTBSY is encountered. Linux treats it as a hard error and returns immediately. Traditionally, the functions execlp() and execvp() ignored all errors except for the ones described above and ENOMEM and E2BIG, upon which they returned. They now return if any error other than the ones described above occurs. SEE ALSO
sh(1), execve(2), fork(2), ptrace(2), fexecve(3), environ(7) COLOPHON
This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
2009-02-22 EXEC(3)
All times are GMT -4. The time now is 09:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy