feat: exec() 函数族:execl() / execlp()

This commit is contained in:
XMuli
2025-04-28 22:48:23 +08:00
parent 008b992ce1
commit f3cb16fa7e
4 changed files with 32 additions and 0 deletions
Binary file not shown.
+12
View File
@@ -0,0 +1,12 @@
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
while (true) {
sleep(1);
printf("hello world\n");
}
return 0;
}
Binary file not shown.
+20
View File
@@ -0,0 +1,20 @@
#include <stdio.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
for (int i = 0; i < 3; i++)
printf("-----i = %d\n", i);
pid_t pid = fork(); //创建子进程
if (pid == 0) {
execl("/bin/ls", "占位参数", "-al", NULL); //ls 程序使用子进程的地址空间
// execl("./hello", "占位参数", NULL); //一般是调用自己的程序,而非系统的程序
}
for (int i = 0; i < 3; i++)
printf("+++++i = %d\n", i);
return 0;
}