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
1
vote
4 answers

Will execv run this in the foreground or background?

I have this in my program: execv (programname, (char **)argv); I'm not sure if the command is actually being executed correctly. How can I find out? Is this being run in the background?
node ninja
  • 31,796
  • 59
  • 166
  • 254
1
vote
1 answer

How do I include variable name within a string of arguments such as: execlp("ls","ls"," /VARIABLE_NAME",Null);?

Basically this, I'd like to include variable within string of exec-related arguments, so if we have: char myname[1024]; myname[1024] = "Michael"; And then when I call execlp I want myname to be injected inside so that "/home/variable" is seen by…
1
vote
2 answers

why `execv` can't use implicit convert from char** to char* const*?

Consider the following code: #include #include void foo(char * const arg[]) { printf("success\n"); } int main() { char myargs[2][64] = { "/bin/ls", NULL }; foo(myargs); execv(myargs[0], myargs); return…
Z E Nir
  • 332
  • 1
  • 2
  • 15
1
vote
1 answer

fork() - have parent process do work without waiting for child process

I'm making a shell in C for a school project that is capable of running processes in parallel if it is commanded to do so. This is the loop of the shell application that waits for commands: while (1) { action = parseShellArgs(); if (action…
Saucy Goat
  • 1,587
  • 1
  • 11
  • 32
1
vote
1 answer

what function in Linux API implements execution of a script file with a shebang?

From https://unix.stackexchange.com/a/2910/674 ... the way shebang (#!) is typically implemented: The kernel opens the executable, and finds that it starts with #!. The kernel closes the executable and opens the interpreter instead. The kernel…
Tim
  • 1
  • 141
  • 372
  • 590
1
vote
0 answers

Linux - misunderstanding of how execv function loads new program

I am currently learning about Linux, and have a question about the execv function. My understanding is that the execv function doesn't create a new process (fork does this), but instead the new program code of the program we wish to run gets…
Engineer999
  • 3,683
  • 6
  • 33
  • 71
1
vote
1 answer

Semaphore blocking children

I have a problem, I would like to do a fork for example a fork of 20processes, this fork created, should not do anything until the last one is not created, and I want to do it with semaphore, how can I implement it? for (i=0; i<20; i++) { switch…
user9039337
1
vote
0 answers

Stdin and stdout to pipe are incorrect after using dup2() to copy to the pipe

My pipe's appear to me to be malfunctioning (although I know I'm doing something wrong). My program 'A1.py' requires input from pipe 'toA1', which it gets fine , it processes the input and sends it's output to 'A2.cpp' via pipe 'toA2'. 'A2.cpp'…
1
vote
1 answer

c execv pass arguments through a function

I'm trying to understand this code: char * pl[] = {"test.sh", NULL}; execv("./test.sh", pl); This will execute my script from a c program, but this will not: execv("./test.sh", ["test.sh", NULL]); This delivers an error message: error: expected…
posop
  • 511
  • 2
  • 7
  • 17
1
vote
2 answers

Windows Service exits when calling an child process using _execv()

I have a C++ Windows application that was designed to be a Windows service. It executes an updater periodically to see if there's a new version. To execute the updater, _execv() is used. The updater looks for new versions, downloads them and stops…
asiouser
  • 11
  • 2
1
vote
3 answers

Copy argv to another variable to change it without change the original

My program has a variable number of args and I need to make an execv with a new path, so I want to change the value of argv[1] in a different variable without changing it, but it won't let me. char** arg_exec = malloc(argc * sizeof (char*)); int…
J. Seixas
  • 57
  • 1
  • 1
  • 9
1
vote
1 answer

Failed execv(/system/bin/dex2oat ) in Android

activity_main_menu.xml
ng2b30
  • 351
  • 6
  • 18
1
vote
2 answers

Quine create and execute file

I am creating a Quine in C and where i need to create a new c file and then compile it and execute it. I made a simple snippet to understand why it's not working. My guess is that execv start the command before fprintf is done writing but i put a…
albttx
  • 3,444
  • 4
  • 23
  • 42
1
vote
0 answers

Handle execv with gdb

I am attaching gdb to a process which used execv to replace the current image. Sadly it seems like this is confusing gdb since when the process eventually std::terminates, all I get are addresses with no symbols. Trying to load the symbols does not…
abergmeier
  • 13,224
  • 13
  • 64
  • 120
1
vote
2 answers

Open/run another program from C and then close this program

How to execute/open/run another program from C, and not block on this but let it run simultaneously. Then I want to to do some test like server/client and then if this has been done I want to just kill/close this program. I have read about system()…
Michał Ziobro
  • 10,759
  • 11
  • 88
  • 143