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
1 answer

Execv Linux printf doesn't work

I'm trying to run executable using this c code: int main(int argc, char *argv[]) { printf("hello.\n"); sleep(2); if (execlp("ls","ls","-l",NULL) == -1) printf("Error occured during execute ls.\n"); return 0; …
1
vote
4 answers

A question about execv and process family relationship

After a process forks and the forked son invokes execv, is the result still the son of the father?
EpsilonVector
  • 3,973
  • 7
  • 38
  • 62
1
vote
1 answer

How to execute a command and read its output in C

I want to find path name with using which command like this: system("which"); and then I use the output for a parameter for execv() function. How can I do that? Any suggestion?
esrtr
  • 99
  • 2
  • 12
1
vote
2 answers

What happens to the parameters to execv?

I was always a bit hazy on this little bit of C magic. When you call execv, you're "replacing the process image." What exactly does that mean? Just the DATA segment? Everything allocated to the process? The stack? The heap? My question is about what…
stu
  • 8,461
  • 18
  • 74
  • 112
1
vote
2 answers

no such file or directory when using execv()

Im trying to write a basic shell that can interpret simple commands like date, ls in the language c. I start by getting the PATH variable like this to later pass it on to the execv() function. const char *name = "PATH"; char *value; value =…
Timo Cengiz
  • 3,367
  • 4
  • 23
  • 45
1
vote
0 answers

fork()/execv() hangs on MPI nodes (C++)

I am writing a C++ program with MPI that will launch external programs on MPI nodes. For this I use fork()/execv(). The problem is that the process starts normally but than freezes at some point if large number of CPUs is used (nCPU > 48). I have…
sda
  • 143
  • 1
  • 10
1
vote
0 answers

is it possible capture the stdout from execv into a file?

I'm using pipes to generate a child process which reads a part from a file and send it through the pipe so the parent process can read it, and execute an extern program and redirect the stdout to a file. The problem is that the stdout of the program…
1
vote
2 answers

How can I pass the redirection operator '>' as an argument for execv?

In the linux terminal, I can type echo hello! > /path/to/file I thought I would be able to do the same thing using execv: #include #include #include int main(void){ char *write_cmd[] = { "echo", "hello!", ">",…
Jay
  • 113
  • 5
1
vote
1 answer

No bash shell generated from ExecV

I'm trying to learn about buffer overflows on my Ubuntu 12.04 32 bit machine by following along with the videos at http://www.securitytube.net/groups?operation=view&groupId=4 . Currently, I'm on part 5, which injects some relocatable code to…
thechico
  • 21
  • 4
1
vote
1 answer

How to capture output of strace in C++ program

I want to analyse the output of strace in my C++ program. While launching /bin/strace ps from my app I get an output from ps, but not from strace and strace output is printed to stdout (my terminal). I use standard technique of using pipes and…
n-canter
  • 268
  • 1
  • 11
1
vote
1 answer

Can't get program executed with execv()

My code is: char* arg_list[] = { "gnuplot", "gnuplot_script.sh", NULL }; printf("Ready %s %s\n", arg_list[0], arg_list[1]); execv( "gnuplot", arg_list ); _exit(EXIT_FAILURE); The output is: Ready gnuplot gnuplot_script.sh but nothing happens…
gsamaras
  • 71,951
  • 46
  • 188
  • 305
1
vote
2 answers

"Unknown Command" error when passing "uname" to execv()

So I have to build a program in C that practically takes a command from keyboard , split it into tokens that are stored in an array and use those tokens as input to "execv" (a command in ubuntu) , I chose the command "uname" with the parameter "-a",…
Alexandru Ianas
  • 95
  • 1
  • 11
1
vote
2 answers

Launching a service from c++ with execv

I'm trying to launch a linux service from a c++ and I do it successfully but one of my process is marked as "defunct" and I don't want that my parent process dies. My code is (testRip.cpp): int main() { char* zebraArg[2]; zebraArg[0] = (char…
Chris
  • 327
  • 2
  • 6
  • 22
1
vote
2 answers

Exec system call without using the path

Which exec system call family members can be used without knowing full path of the given command. For example when "/bin/ls -t" "/bin/cat -n" "/usr/bin/tr /a-z/ /A-Z/" inputs given from the commandline I can properly use execv(arg[0],args) like…
user3117189
  • 69
  • 3
  • 9
1
vote
3 answers

If I fork() and then do an execv(), who owns the console?

I am writing a Linux application. What happens if I call fork() and then run an application that takes console input? Consider the code below: int process_id = fork(); if (process_id != 0) { /* this is the parent process */ error =…
boltup_im_coding
  • 6,345
  • 6
  • 40
  • 52