Questions tagged [execv]

int execv(const char *path, char *const argv[]); Like all of the exec functions, execv replaces the calling process image with a new process image. This has the effect of running a new program with the process ID of the calling process. The command-line arguments are passed to the function as an array (Vector) of pointers.

The POSIX standard declares exec functions in the unistd.h header file, in C language. The same functions are declared in process.h for DOS and Microsoft Windows.

When execv() is successful, it doesn't return; otherwise, it returns -1 and sets errno.

185 questions
10
votes
2 answers

How to make gdb follow execv? Not working despite "follow-exec-mode"

i've written two simple programs: int main(int ac, char **argv ) { execv( "/home/me/Desktop/execvtest2", argv ); } and int main(int ac, char **argv ) { execv( "/home/me/Desktop/execvtest1", argv ); } I've compiled them with gcc -g to the…
roemer
  • 537
  • 1
  • 5
  • 21
6
votes
2 answers

Call an external program from within OCaml

I'm pretty new to OCaml and was trying to figure out how to call an external program from within OCaml. I've been following the documentation here, and making the following call: Unix.execv "cat text_file";; This returns the following: string array…
achinda99
  • 5,020
  • 4
  • 34
  • 42
6
votes
1 answer

prctl(PR_SET_PDEATHSIG, SIGNAL) is called on parent thread exit, not parent process exit

I have a process that is forking to a child process. The child process should not exist if the parent process exists. So, I call ::prctl(PR_SET_PDEATHSIG, SIGKILL) in the child process to kill it if the parent dies. What ends up happening is the…
user1418199
  • 257
  • 1
  • 3
  • 7
5
votes
3 answers

Cross-platform way to specify Python interpreter when running with execv

I am currently running a Python scripts both on Linux and Windows 7. The file is executed in an execv style with which I mean that the interpreter is defined in the beginning of the file in a command. In Windows system, the interpreter specification…
jsalonen
  • 29,593
  • 15
  • 91
  • 109
5
votes
4 answers

execv and fork: inform parent that child failed to execute the file

How can the master process know that the child process failed to execute the file (e.g. no such file or directory)? For example, in the following code, how can we get run() to return something other than 0? Thanks! #include #include…
psilouette
  • 83
  • 1
  • 6
4
votes
3 answers

How to bring a child process running in the background to the foreground

If I used fork() and execv() to spawn several child processes running in the background and I wanted to bring one of them to the foreground, how could I do that? I am trying to write a shell that can start processes either in the foreground or…
node ninja
  • 31,796
  • 59
  • 166
  • 254
4
votes
1 answer

How to convert properly char * const[256] to const char * const*

I have this struct: typedef struct cmdLine { char * const arguments[256]; } cmdLine; I also have an argument cmdLine *pCmdLine. I want to use execvso I write execv((pCmdLine->arguments[0]), pCmdLine->arguments);. The second argument doesn't feet…
J. Doe
  • 299
  • 3
  • 12
4
votes
1 answer

Calling execv after creating a thread

I'm very new to threads, processes, execv, etc. I have researched and found that when you execute an execv, it takes the space of the calling process. I am wondering what happens when you create a thread in main, and then call execv, directly after…
unconditionalcoder
  • 723
  • 1
  • 13
  • 25
4
votes
3 answers

Would this be considered a memory leak?

Consider this pointless program: /* main.c */ #include #include int main(int argc, char **argv) { int i; for (i = 0; i < 1024; i++) { int pid = fork(); int status; if (pid) { …
Nick
  • 187
  • 2
  • 6
4
votes
1 answer

waitpid - WIFEXITED returning 0 although child exited normally

I have been writing a program that spawns a child process, and calls waitpid to wait for the termination of the child process. The code is below: // fork & exec the child pid_t pid = fork(); if (pid == -1) // here is error handling code…
Andreas Grapentin
  • 5,499
  • 4
  • 39
  • 57
4
votes
4 answers

Writing own Unix shell in C - Problems with PATH and execv

I'm writing my own shell in C. It needs to be able to display the users current directory, execute commands based on the full path (must use execv), and allow the user to change the directory with cd. This IS homework. The teacher only gave us a…
user1287523
  • 967
  • 3
  • 14
  • 31
4
votes
6 answers

How to use execv() without warnings?

I am working on MacOS-X Lion with GCC 4.2. This code works, but I get a warning I would like fix: #include main() { char *args[] = {"/bin/ls", "-r", "-t", "-l", (char *) 0 }; execv("/bin/ls", args); } warning: deprecated…
Pietro
  • 12,086
  • 26
  • 100
  • 193
3
votes
2 answers

redirecting output of execvp into a file in C

I don't know what I am doing wrong... but here is the snippet of code that is being executed: if (fork() == 0) { // child int fd = open(fileName, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); dup2(fd, 1); // make…
user1162954
  • 267
  • 2
  • 4
  • 7
3
votes
1 answer

How to inherit stdin and stdout in python by using os.execv()

First, I wrote a c++ code as follows: #include int main() { int a,b; while(scanf("%d %d",&a,&b) == 2) printf("%d\n",a+b); return 0; } I use g++ -o a a.cpp to complie it. Afterwards, I wrote python code as…
luyi0619
  • 313
  • 3
  • 8
3
votes
1 answer

Execve with argument in x64 with gnu asm

I am trying to write a shellcode in GNU asm for linux and i'm unable to call execve with arguments. What i'm trying to do : execve("/bin/ls", ["/bin/ls", "-la", NULL], NULL); this is my code : .section .text .globl _start _start: push $0x3b …
Ewen Brune
  • 33
  • 4
1
2 3
12 13