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

execv works for "/bin/ls" but not "pwd"

I am new to C programming language on Unix and trying to build a shell-like C program. However the program gives error if I try to change the function according to my own choices. For example as it seems /bin/ls -l is working but pwd is not. It may…
Cemil Çakmak
  • 149
  • 1
  • 12
3
votes
1 answer

reading from stdin after execl() bash return an eio(Input/output error)

The following code can act as expected if executed by a shell. But if I set this program as a user's shell and ssh into the host to execute this program as a shell, the read(0, &buf123, 1); will return an EIO(Input/output error): #include…
user2828102
  • 125
  • 1
  • 12
3
votes
2 answers

C-program does not return from wait-statement

I have to migrate a C-program from OpenVMS to Linux, and have now difficulties with a program generating subprocesses. A subprocess is generated (fork works fine), but execve fails (which is correct, as the wrong program name is given). But to reset…
3
votes
3 answers

Executing a command from C++, What is expected in argv[0]?

I am using execv() to run commands from /bin/ such as 'ls', 'pwd', 'echo' from my c++ program, and I am wondering what value I should provide in argv[0]; const char * path = getPath(); char ** argv = getArgs(); execv(path,argv);
Tom Neyland
  • 6,860
  • 2
  • 36
  • 52
3
votes
5 answers

C++ fork() and execv() problems

I am kind of newbie on C++, and working on a simple program on Linux which is supposed to invoke another program in the same directory and get the output of the invoked program without showing output of the invoked program on console. This is the…
Ahmet Keskin
  • 1,025
  • 1
  • 15
  • 25
2
votes
0 answers

Userfaultfd fails register with ENOMEM after execv

I have a program (parent.rs) that will: Fork Create a userfaultfd on the child, then transfer it to the parent (with pidfd_getfd). Execs the child (child.rs) Child allocates memory with mmap and "sends" it to the parent Parent receives the memory…
Filipe Rodrigues
  • 1,843
  • 2
  • 12
  • 21
2
votes
1 answer

Execv with arguments starting from second element

I am making a program that can take another program as an argument and run it. I am using execv() to run the second program, but how can I use argv[] (that comes from the main program, is a char*) as arguments for execv()? The first element of…
ha7008
2
votes
1 answer

Creating the execv argument array when the arguments are unknown at compile time

I am trying to revive an in-house CAM application, i.e. get it to compile on a current gcc so I can maintain it. I have 27 years of experience as an occasional C/C++ hack ;-) The part in question is the command-line core, so no UI. It has a sort of…
2
votes
1 answer

os.execv PermissionError Errno13 Permission denied

I am trying to run the same program recursively but with a different argument. I am doing it like this: os.execv(file_dir, ['python'] + [sys.argv[0]] + [str(last_line)]) quit() This is a snippet of a function that i call from my main function. I…
giulio di zio
  • 171
  • 1
  • 11
2
votes
1 answer

Time the duration of a program called by execv

I am making a C program that uses fork and execv to run other programs in parallel. I can't seem to be able to time the duration of the execution of the program called by execv since the new process dies immediately after that program is done…
Saucy Goat
  • 1,587
  • 1
  • 11
  • 32
2
votes
4 answers

Does the C execv() function terminate the child proccess?

Heres a breakdown of my code. I have a program that forks a child (and registers the child's pid in a file) and then does its own thing. The child becomes any program the programmer has dignified with argv. When the child is finished executing, it…
Chris Allen
  • 653
  • 4
  • 9
  • 17
2
votes
1 answer

How to pass argument (which is a command instead of file name) to new shell using execve?

I am trying to send arguments(e.g:ls,date,cal) to a new shell ,execute those arguments and terminate. #include"header.h" //includes all the header files int main(int argc,char * argv[],char *envp[]) { char *ap[]={"sh","ls",NULL}; int…
2
votes
1 answer

Weird behaviour after calling execv

I am trying to execute a command using execv. After running this program, I can see the statement "Going to call execv!" being printed on the standard output. I can also see the prints from the program "leaky". Actually everything is working as…
aniztar
  • 45
  • 4
2
votes
2 answers

How to use fork() in Visual Studio 2015? (Windows 7 Professional)

I searched around and all I could find was that I needed Cygwin. I installed it but I can't seem to find unistd.h anywhere in C:\cygwin64\usr\include. Of course, I added that path to the "Include Directories" in my Project in VS2015. What I want to…
2
votes
1 answer

assigning linux capability to one java process

I run many java processes but I just want to assign cap_net_raw linux capability to just one java process. Currently if I do this "setcap cap_net_raw=ep /usr/java/default/bin/java" then this capability get assigned to all java processes. After…
Santi
  • 67
  • 7
1
2
3
12 13