logo

Crowdly

Browser

Add to Chrome

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

✅ The verified answer to this question is available below. Our community-reviewed solutions help you understand the material better.

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;

}

More questions like this

Want instant access to all verified answers on moodle.coep.org.in?

Get Unlimited Answers To Exam Questions - Install Crowdly Extension Now!

Browser

Add to Chrome