在 Linux 中,您可以使用 fork 函数创建一个子进程,并使用 exec 函数来运行 shell 命令 "ls" 和 "ls -a" 来统计指定目录下的文件总数和隐藏文件数量。下面是一个示例代码:
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main() {
int total_files = 0;
int hidden_files = 0;
int fd[2];
if (pipe(fd) < 0) {
perror("pipe");