opendir

dr-x------ 2 root root  0 11月  6 17:10 .
dr-xr-xr-x 9 root root  0 11月  6 17:10 ..
lrwx------ 1 root root 64 11月  6 17:11 0 -> /dev/pts/5
lrwx------ 1 root root 64 11月  6 17:11 1 -> /dev/pts/5
lrwx------ 1 root root 64 11月  6 17:11 2 -> /dev/pts/5
lrwx------ 1 root root 64 11月  6 17:11 3 -> /home/chance/git-workspace/LinuxDevelopment/CodeTestZone/smallTest/test.txt

lr-x------ 1 root root 64 11月  6 17:11 4 -> /proc/4962/fd



int main()
{
        int fd = open("test.txt",O_RDWR|O_CREAT,S_IRUSR,S_IWUSR);

        pid_t processID = getpid();

        cout << processID<<endl;
        char id[30];
        snprintf(id,30,"%d",processID);

        string path = "/proc/";
        path += id;
        path += "/fd/";
        DIR * pDir = opendir(path.c_str());

        sleep(100);

        close(fd);
        closedir(pDir);

        return 0;
}





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章