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
2 answers

How can I keep execv from killing my program?

My assignment is to write a simple linux shell. I'm on external commands. We need to use execv. for (int i = 0; i < count; i++){ char path[1024]; strcpy(path, PATHS[i]); // PATHS is an array of cstrings, the paths in $PATH …
d0m1n1c
  • 157
  • 4
  • 16
1
vote
2 answers

Illegal Argument Execv() Unix C++

So I basically have a vector args with 1 argument per array that I'm trying to pass to an execv() call in unix. Execv accepts two parameters like so: int execv(const char *path, char *const argv[]); What's the best way to convert my vector of…
rideon88
  • 298
  • 2
  • 12
1
vote
2 answers

fork() kill() and execv()

I'm trying a small unit-testing here. But the program doesn't work as I expected. char *args[2]; args[0] = (char*)"/usr/bin/firefox"; args[1] = NULL; pid = fork(); printf("forked and my pid is %d\n",pid); //check for errors …
Alon_T
  • 1,430
  • 4
  • 26
  • 47
1
vote
1 answer

I want to redirect the execv of ls in a file and then in a pipe, why is not working?

First of all, I want to redirect the output of ls (exec) in a file and then from a file to pipe, why is not working? It's ok when I redirect in a file, but that's all. How can I do to find the length of the output of ls? (that's why I did a…
1
vote
1 answer

Trouble with fork and execve

So for a class assignment we're making our own basic shell. Among other functions, it has to be able to process absolute paths and execute external applications using fork() and execv. The idea is the program forks a child process, calls execv…
Scott
  • 17
  • 1
  • 2
  • 4
1
vote
3 answers

Writing a shell in C, doesn't return anything

I run my shell and it prompts: "Shell>". I type a command, like ls, and it just makes a new line that says "Shell>" again. Any idea why it doesn't seem to be hitting execv? int no_of_args = count(buffer); // plus one to make…
user1687558
  • 83
  • 1
  • 7
1
vote
2 answers

How execv gets the output from pipe?

referring to the old homework question : /* implementing "/usr/bin/ps -ef | /usr/bin/more" */ using pipes. #include #include #include int main() { int fds[2]; int child[2]; char *argv[3]; pipe(fds); if…
dejavu
  • 3,236
  • 7
  • 35
  • 60
0
votes
1 answer

stdin to parent process blocked when calling execv

I have created an application that launches a couple of child processes using fork and execv. string process; //initialized before execv call char** process_args; //initialized before execv call int pid = fork(); if(pid == 0) { …
zsalzbank
  • 9,685
  • 1
  • 26
  • 39
0
votes
3 answers

running mysql import from execv

pid_t childPid = fork (); if (childPid == (pid_t) 0)//zero success { const char *path = "/usr/local/mysql/bin/mysql"; //doesn't work //char * const parmList[] = {"--user=root", "test_db", NULL}; //does work char * const…
joels
  • 7,249
  • 11
  • 53
  • 94
0
votes
1 answer

How to stop writing to a file execv

I am trying to write only to a file when a user specifies which file to write in with ">". The first iteration works fine, but when a user types any command after the one where they specified the file to write to with ">" it still writes to the…
Wragnam
  • 19
  • 2
0
votes
1 answer

execv and testing correct absolute paths

I'm trying to test absolute paths on a linux machine to find where a program is located so I can run it with my specific arguments. The problem is, when I find it, I keep adding more strings to the correct path as well as memory leak by freeing the…
GFXGunblade
  • 97
  • 3
  • 10
0
votes
0 answers

Passing arguments to execv() system call

I'm trying to build a version of a linux shell wherein, I take in the commands from the user and execute the commands using execv() system call. I'm using strtok_r to tokenize the commands and pass the arguments to execv(). For example, when the…
0
votes
2 answers

Execv with argument array

I have a simple C program that creates an array of arguments as required by the second argument of execv() that executes a program that computes and outputs the Caeser Cipher decoding of the argument. However the file calling execv() seems to ignore…
Panda
  • 19
  • 5
0
votes
1 answer

Standard functions in C99 being called "Implicit declarations"

I have a C program that I am running on my MacOS terminal. All command line tools and GCC compiler have been installed. However for using functions like getpid() or execv() it gives the following error: execv-test.c:7:35: error: implicit declaration…
Panda
  • 19
  • 5
0
votes
1 answer

c pipe ls returned strings to parent

I'm currently trying to run an ls command in my C code and then pipe the outputted strings to the parent process via a fd. The problem I'm currently facing is, that I execv the ls command but I don't know how to store the strings (if that is even…