Questions tagged [execl]

execl() is a C library function which is used to replace the current process image with a new process image. It belongs to the family of exec() functions and prototyped in unistd.h.

execl() is a C library function which is used to replace the current process image with a new process image. It belongs to the familt of exec() functions and prototyped in unistd.h.

The Function Prototype

int execl(const char *path, const char *arg, ...);

where,

  • The first argument is the name of a file that is to be executed.
  • The const char *arg and subsequent arguments (if any) can be thought of as arg0, arg1, ..., argn. Together they describe a list of one or more pointers to null-terminated strings that represent the argument list available to the executed program.

Return Value

The various exec() functions only return if an error has occurred. The return value is -1, and errno is set to indicate the error.

Check the Main page for more details.

120 questions
116
votes
7 answers

Please explain the exec() function and its family

What is the exec() function and its family? Why is this function used and how does its work? Please anyone explain these functions.
user507401
  • 2,809
  • 9
  • 25
  • 20
6
votes
2 answers

C - Junk characters on output

Let's say, I have two programs - input.c & output.c All I want to do is send some payload/characters in "half pyramid" format into another one using execl() function. input.c #include #include #include #include…
Yeez
  • 282
  • 1
  • 3
  • 9
4
votes
2 answers

Why does execl require me to hit "Enter" after running a process?

In bash, when I type ls and hit enter, the binary ls will run and I will return to shell prompt again without doing anything from my side. However this program, written in C will block: #include #include #include…
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
4
votes
1 answer

How can I change a number to a variable in C?

I would like to know how to substitue the value of a variable in C. execl ("/bin/cat","cat","/proc/30828/status", (char *)0 ); I would like to be able to change the "30828" to a variable, because this value isn't fixed. I am wondering if it would…
user3671361
  • 175
  • 4
  • 15
3
votes
1 answer

C SECCOMP blocks or closes STDIN/STDOUT

I am now implementing to run another program in child process after fork. int main(int argc, char *argv[]) { pid_t pid = 0; int status; struct user_regs_struct regs; prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0); …
pincoin
  • 665
  • 5
  • 19
2
votes
2 answers

Why do programs with arguments passed in argc and argv get different results when executed in different ways

void main(int argc,char *argv[]) { for (int i = 0; i < argc; i++) { printf("%s ", argv[i]); } } when I use command ./test 1 2 3 in terminal to execute this program, I got result ./test 1 2 3 ,but when I use function…
Mr Right
  • 35
  • 4
2
votes
1 answer

expected ')' before '(' token when using NULL macro in C

This is my code for a program that creates an environment to run a Java .jar file. I am using the _execl function and am programming on Windows: #include #include #include int setenv(const char *name, const char…
Abstrogic
  • 37
  • 2
2
votes
3 answers

execl parameters confusion

Why does the command execl("/bin/ls", NULL); return a usage error, whereas the command execl("/bin/ls", "badfsafds", NULL); return a list of files in the directory in a simple C program? I know that the first parameter of execl is path…
Math Student
  • 21
  • 1
  • 3
2
votes
0 answers

c - execl`d program doesn't give promt back

EDIT: THE QUESTION IS ANSWERED IN COMMENTS So, i'm studying pipes. Long story short, i have two programs: first program creates a pipe and two forks: first fork closes read descriptor and writes some stuff to write one (then closes it), second fork…
Anton Tretyakov
  • 303
  • 1
  • 9
2
votes
2 answers

Why should one exec "sh -c a.out" instead of a.out itself?

I'm studying Apple's implementation of popen() at https://opensource.apple.com/source/Libc/Libc-167/gen.subproj/popen.c.auto.html and noticed that they do execl(_PATH_BSHELL, "sh", "-c", command, NULL) instead of execl(_PATH_BSHELL, command,…
StoneThrow
  • 5,314
  • 4
  • 44
  • 86
2
votes
0 answers

Why do the exec()-family functions actually return a value?

In a book about Linux and Unix programming, I´ve found this statement (emphasize mine): "All functions (exec()-family) return -1 in the case of an error. Otherwise at successful execution there is no return back to the calling program. Thus, it is…
2
votes
3 answers

Parellel processes using fork() with command line parameters in C

I am trying to create a program that takes in command line a number of counts to do and does them in parallel. I have one count.c file that is used to make the counting : int main(int argc, char** argv) { assert(argc>1); int length=…
CSstudZ
  • 101
  • 10
2
votes
0 answers

How to execute shell command with arguments in C

I'm unable to execute the command alone, with arguments is working. How can I make it work both ways. char command[256]; char args[10][256]; char buffer[256] __attribute__((aligned(4096))); Funcion is handling command and arguments and I'm sure…
2
votes
1 answer

C Get pid of process launched with execl

I'm launching a process with the instruction execl("./softCopia","softCopia",NULL); softCopia is just a dummy that writes integers in a file. I would like to know how can i get the pid of this process?
Asdemuertes
  • 313
  • 3
  • 6
  • 19
2
votes
1 answer

Calling "ps" command with arguments with execl has unexpected behaviour

I wrote a simple C program that uses the execl function. What I'm expecting to see after running this program is the output of ps -U myusername. If writing ps -U myusername in terminal, I get the desired result. If calling execl("/bin/ps",…
Ionut Marisca
  • 257
  • 4
  • 10
1
2 3 4 5 6 7 8