logo

Crowdly

Consider the following code and MAP the file to which each fd points at the end ...

✅ Перевірена відповідь на це питання доступна нижче. Наші рішення, перевірені спільнотою, допомагають краще зрозуміти матеріал.

Consider the following code and MAP the file to which each fd points at the end of the code. Assume that files/folders exist when needed with proper permissions and open() calls work.

 

int main(int argc, char *argv[]) {

    int fd1, fd2 = 1, fd3 = 1, fd4 = 1;

    fd1 = open("/tmp/1", O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR);

    fd2 = open("/tmp/2", O_RDDONLY);

    fd3 = open("/tmp/3", O_WRONLY | O_CREAT, S_IRUSR|S_IWUSR);

    close(0);

    close(1);

    dup(fd2);

    dup(fd3);

    close(fd3);

    dup2(fd2, fd4);

    printf("%d %d %d %d\n", fd1, fd2, fd3, fd4);

    return 0;

}

Більше питань подібних до цього

Хочете миттєвий доступ до всіх перевірених відповідей на moodle.coep.org.in?

Отримайте необмежений доступ до відповідей на екзаменаційні питання - встановіть розширення Crowdly зараз!