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
votes
0 answers

Search multiple folders for .sh file C

I am trying to run an sh script using execv. I have an array "path" which contains all the folders to search in. How can I use the execv command, or any of the other exec libraries to search all directories in the path array to see if the .sh file…
Wragnam
  • 19
  • 2
-1
votes
2 answers

Two parallel program execv with fork with returning to code

I'm writing pseudo-shell and now write parallel-command functionality. In this question ( Differences between fork and exec ) I'm found how I can call execv with returning to my code execution. But I don't understand how I can call two parallel…
bazylevnik0
  • 60
  • 1
  • 7
-1
votes
1 answer

Execv function in C not reading a variable that is passed in as an argument

So I am building my own shell and one of the commands I want is the "cat" function. To do this, I am using the execv function and passing in the correct bin path of "cat" as well as the file name that I want to concatenate and print to the…
-1
votes
2 answers

What do I check for in this if statement?

I am using sscanf to read user input and save to several outputs. As far as my understanding goes, if I have sscanf(iput, %s %s %s %s, arr[0], arr[1], arr[2], arr[3]) I can have up to 4 items entered, but it does not require 4; meaning I could just…
-1
votes
1 answer

After fork, execv communicates with the parent process when executing the target program

I know that the signal handler cannot be inherited when call execv in the child process of fork, so I wonder if the execv process can be piped to communicate with the parent process. As far as I know, pipe communication requires parenthood or a…
gazile
  • 105
  • 6
-1
votes
1 answer

Passing ">>" as an execv argument?

I am trying to pass some arguments into an execv call: char *const paramList[] = {"/bin/grep", "-rn", "comrade", "/home/sgspectra/Documents/testing_grep/", ">>", "output.txt", NULL}; I believe…
sgspectra
  • 3
  • 2
-1
votes
1 answer

Fork doesn't load the program in execv

Below program neither load the program to child process nor prints "before" and "after". However ps aux shows the creation of processes (but without loading args0 program). I am using PIPE defined as socketpair. args0[] holds executable name for the…
joy_jlee
  • 103
  • 2
  • 13
-1
votes
1 answer

Arguments being passed into execv in C

I am writing a program in C that forks and uses execv to call a command that is passed in to the original function. So I would type in something like "./program echo "hello"" and the child of the fork in my program would use the bash command "echo…
zdale
  • 5
  • 1
  • 5
-1
votes
2 answers

TCP client / server : when stop read socket

I am facing multiple problem creating a small ftp like client / server (tcp) the client have a prompt. the How to stop receiving issue. Sending data throught my socket from my client to server or vise-versa. For example, from the server sending some…
albttx
  • 3,444
  • 4
  • 23
  • 42
-1
votes
1 answer

Trying to add an after-queue mail filter in Postfix on CentOS, get execvp permission denied

So I followed [the guide][1] on how to set up a simple mail filter with Postfix, so that I can do a find-replace in the body of outgoing emails. I created a script at /tmp/mailfilter.sh, and changed the /etc/postfix/master.cf file as instructed #…
Sossisos
  • 1,569
  • 2
  • 10
  • 19
-1
votes
1 answer

What happens to the current program after execv function call?

Let's say that at some point in my program I am using execv and the function ran successfully. Now my program has changed. What happened to it exactly? (Is all the memory get wiped automatically?)
LiorGolan
  • 355
  • 1
  • 4
  • 11
-1
votes
1 answer

How to use execv to run a program with sudo?

I read a lot of posts before asking this question unfortunatly none of them gave me the required solution for my problem. I am writing a mpi program with gnu c and try to execute hping3 inside a previous child process. Actual status is, that i can…
lt_katana
  • 148
  • 3
  • 12
-1
votes
1 answer

Can't run execv

I've been trying to run command using exevp as follows: char *args[11]; args[0] = (char*)lgulppath.c_str(); args[1] = (char*)"-i"; args[2] = (char*)sniffer_interface.c_str(); args[3] = (char*)"-r"; args[4] = (char*)pcapfileLimit.c_str(); args[5] =…
Alon_T
  • 1,430
  • 4
  • 26
  • 47
-2
votes
2 answers

Create Char* array dynamically in C

I am trying to create a char* array dynamically for execv. The number of parameters is known only at runtime. This is my code: char *id_array= malloc((size_array) * sizeof(char)); int length = 4 + groupId_list.nr; //groupId_list.nr know only at…
mani
  • 3
  • 6
-2
votes
2 answers

How to get directory of exec files of any commands on terminal in C?

I am rewriting the problem since it's not clearly understood as far as I see. I implement my own shell in C which needs to support all commands the original one does. The problem is to execute all existing UNIX bash commands in C without using…
Yusuf Kamil AK
  • 771
  • 8
  • 17
1 2 3
12
13