OpenDir 错误 /proc 文件:没有那个文件或目录

时间:2021-06-17 15:57:17

标签: c file directory operating-system system

我正在尝试使用以下 C 代码打开 /proc 目录(目的是读取 PID 和其他一些正在运行的进程的详细信息),但它给出了错误“没有这样的文件或目录”,但我可以浏览在终端中使用 unix 命令的 proc 目录。

有人能说出我的代码有什么问题吗?

#include<stdio.h>
#include<dirent.h>

int main(void)
{
    DIR *procdir;
    if(!(procdir=opendir("/proc"))){
        perror("opendir failed!");
    }
    return 0;
}

Unix 命令:

$ ./a
opendir failed!: No such file or directory

MINGW64 ~/unix
$ /proc
bash: /proc: Is a directory

MINGW64 ~/unix
$ cd /proc

MINGW64 /proc
$ ls
465      cygdrive     loadavg  mounts      registry    self   sys      
version
503      devices      meminfo  net         registry32  stat   sysvipc
cpuinfo  filesystems  misc     partitions  registry64  swaps  uptime

0 个答案:

没有答案