- 添加了一个新的演示课程示例代码文件 `/process_basic/daemon/mydaemon.c` - 实现了一个单实例守护进程的示例代码 - 添加了一个新的演示课程示例代码文件 `/process_basic/system.c` - 实现了一个使用系统调用 `system()` 执行命令的示例代码 - 添加了一个新的演示课程示例代码文件 `/process_basic/system1.c` - 实现了一个使用进程相关系统调用 `fork()`、`execl()` 和 `wait()` 的示例代码
38 lines
549 B
C
38 lines
549 B
C
#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);
|
|
} |