✨ 新功能:添加演示课程示例代码 (C13 Linux进程基础)
- 添加了一个新的演示课程示例代码文件 `/process_basic/daemon/mydaemon.c` - 实现了一个单实例守护进程的示例代码 - 添加了一个新的演示课程示例代码文件 `/process_basic/system.c` - 实现了一个使用系统调用 `system()` 执行命令的示例代码 - 添加了一个新的演示课程示例代码文件 `/process_basic/system1.c` - 实现了一个使用进程相关系统调用 `fork()`、`execl()` 和 `wait()` 的示例代码
This commit is contained in:
38
C13-Linux系统编程/process_basic/system1.c
Normal file
38
C13-Linux系统编程/process_basic/system1.c
Normal 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);
|
||||
}
|
||||
Reference in New Issue
Block a user