FAQ Database Discussion Community


Why cant I use char **myargs instead of char *myargs[3] while calling execvp()?

c,gcc,child-process,execvp
I have a C program to create a child process to run command "wc exec.c". Below is the program. /* Filename: exec.c*/ #include<stdio.h> #include<sys/wait.h> #include<unistd.h> #include<stdlib.h> #include<string.h> int main(int argc, char **argv) { printf("Hello world (pid = %d).\n",(int) getpid()); int ret = fork(); if (ret < 0) { fprintf(stderr,"fork failed.\n");...

Writing a simple shell in C using fork/execvp

c,linux,bash,shell,execvp
I have to develop a simple shell in C using system calls fork()/execvp(). So far my code takes in a command, splits it up using strtok into an array argv and then I call fork to create a child and execute the command. Im working on this in ubuntu where...

Infinite Loop with execvp in C

c,shell,fork,infinite-loop,execvp
This program is supposed to be shell which executes commands entered by the user. My program worked fine until I made it accept flags as well as commands. Now, the program loops infinitely at execvp. Any command entered will do this(I've primarily been testing with ls -l). If it matters,...

What is wrong with my execvp usage?

c,linux,exec,fgets,execvp
I'm writing a small shell to learn C. Now I want to execute custom commands but it is not working. $ ./a.out OS>ls 10357: executing ls failed to execute ls : (2: No such file or directory) I must not use system call to execute custom command, I should use...

How to use in-line expansion with execvp

c,linux,execvp
I am interested in, how can one accomplish in-line linux expansion with execvp in C. I tried doing so with a backslashed apostrophe inside the one that indicates, that the following is a string, but failed. The code, that I run is as it follows: static const char *datecmd[] =...

execvp() never finishes on pipe

c,printf,pipe,echo,execvp
I am taking an OS course and writing a shell. And I encountered a problem about execvp() and pipe. The following code is a simplified version of the code where problem happens. static pid_t command_exec(command_t *cmd, int *pass_pipefd) //the function that executes commands. this function will be called multiple times...