execs(3)
π execs β bestie, let's execute some files π
okay so this is the execs(3) page from the Linux Programmer's Manual, and it's genuinely so useful, like, i need you to focus for two seconds π«Ά
β¨ NAME β¨
execs, execsp, execspe β execute a file taking its arguments from a string π
like. the whole vibe is: you got a string, you wanna run a program with it. slay.
πΈ SYNOPSIS πΈ
#include <unistd.h>
#include <execs.h>
int execs(const char *path, const char *args);
int execse(const char *path, const char *args, char *const envp[]);
int execsp(const char *args);
int execspe(const char *args, char *const envp[]);
int eexecs(const char *path, char *args);
int eexecse(const char *path, char *args, char *const envp[]);
int eexecsp(char *args);
int eexecspe(char *args, char *const envp[]);
These functions are provided by libexecs and libeexecs, so when you link you gotta go -lexecs or -leexecs. don't forget it bestie, the linker will be SO dramatic about it π
π¦ DESCRIPTION π¦
This whole little group is the glow-up of the exec(3) family that libc already gives you. like, it's giving "we extended the friend group" β¨
So here's the tea, one by one:
execsis the bestie ofexecv(3)execseis the bestie ofexecve(2)execspis the bestie ofexecvp(3)execspeis the bestie ofexecvpe(3)
Same energy, same job, BUT β and this is the iconic part β they take the command line arguments for the file to execute (and also the command name, for execsp(3) and execspe(3)) by parsing a command string called args. no cap. π
Now, how does that parsing work? bestie, i got you:
- Command arguments inside args are delimited by space characters β that's blanks, tabs, or new lines. any of them, all of them, go off.
- You can wrap stuff in single or double quotes to delimitate command arguments that include spaces. so
"hello world"stays one argument, as it should π - A non quoted backslash (
\) is the escape character, and it protects the next char. very "don't touch my little guy" of it π«Ά
And here's the lowkey important distinction, don't skip this part:
execs,execse,execspandexecspedo not use dynamic allocation, but they need space on the stack to store an entire copy of args. so it's like, cozy, but it's eating your stack, okay?eexecs,eexecse,eexecspandeexecspedo not use extra stack space, but they modify args. periodt. your string comes back different, so don't come crying to me π
π‘ little pro tip straight from the source: if you're gonna use the same argv for several exec commands, use s2argv(3) to parse the args just once. efficiency queen behavior π
π RETURN VALUE π
These functions return only if an error has occurred. like, if everything went right, they literally never come back β you're someone else's process now, main character energy β¨
The return value is always -1. and the failure cases and errno values? those are the ones specified for execve(2). same rules, same lore, no new ones invented π
π EXAMPLE π
okay so this little program demonstrates the use of execs. it's cute, it's simple, it eats:
#include <stdio.h>
#include <unistd.h>
#include <execs.h>
#define BUFLEN 1024
int main(int argc, char *argv)
{
char buf[BUFLEN];
printf("type in a command and its arguments, e.g. 'ls -l'\n");
if (fgets(buf, BUFLEN, stdin) != NULL) {
execsp(buf);
printf("exec error\n");
}
}
see how it types in a command, parses it, and just goes? and if you ever see that exec error print, that means the exec did not pop off π
π§ SEE ALSO π§
go read those too, i'm obsessed with them fr fr π
π BUGS π
Found a bug? bestie, don't suffer in silence. Bug reports should be addressed to <info@virtualsquare.org> π«Ά
π AUTHOR π
Renzo Davoli <renzo@cs.unibo.it> β an actual icon, we stan π
and that's the whole page, bestie!! this one came from VirtualSquare, dated 2014-05-27, and it's the execs(3) page, okurrr π now go execute something (a file. from a string. responsibly) πβ¨π¦
π¦ where this page comes from
- debian bookworm: libexecs-dev 1.3-2 Β· LGPL-2.1-or-later
- debian trixie: libexecs-dev 1.4-2+b2 Β· LGPL-2.1-or-later
- ubuntu jammy: libexecs-dev 1.3-1 Β· LGPL-2.1-or-later
- ubuntu noble: libexecs-dev 1.4-2build1 Β· LGPL-2.1-or-later
- ubuntu questing: libexecs-dev 1.4-2build1
- ubuntu resolute: libexecs-dev 1.4-2build2 Β· LGPL-2.1-or-later
- ubuntu stonking: libexecs-dev 1.4-2build2 Β· LGPL-2.1-or-later
- Copyright (C) 2014 Renzo Davoli. University of Bologna. <renzo@cs.unibo.it>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms