mirror of
https://github.com/XMuli/QtExamples.git
synced 2026-10-29 12:40:08 +08:00
feat: exec() 函数族:execl() / execlp()
This commit is contained in:
Binary file not shown.
@@ -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.
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user