新功能:添加演示课程示例代码 (C13 Linux进程基础)

- 添加了一个新的演示课程示例代码文件 `/process_basic/daemon/mydaemon.c`
  - 实现了一个单实例守护进程的示例代码
- 添加了一个新的演示课程示例代码文件 `/process_basic/system.c`
  - 实现了一个使用系统调用 `system()` 执行命令的示例代码
- 添加了一个新的演示课程示例代码文件 `/process_basic/system1.c`
  - 实现了一个使用进程相关系统调用 `fork()`、`execl()` 和 `wait()` 的示例代码
This commit is contained in:
lzy
2024-05-16 05:30:31 +08:00
parent 0ee62429a2
commit cb969dfd41
4 changed files with 222 additions and 10 deletions

View File

@@ -0,0 +1,38 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
/**
* @brief few: folk, execl, wait
* @details
*
* @param argc
* @param argv
* @return int
*/
int main(int argc, char **argv)
{
pid_t pid;
fflush(NULL);
pid = fork();
if (pid < 0)
{
perror("fork()");
exit(1);
}
if (0 == pid) // child
{
execl("/bin/sh", "sh", "-c", "date +%s", NULL);
perror("execl()");
exit(1);
}
wait(NULL);
exit(0);
}