Linux OS Management Question:
Download Questions PDF

Below is the code:

int main() {
int fd1, fd2;
struct stat buff1, buff2;
fd1 = open("1.txt", O_RDWR);
fd2 = open("2.txt", O_RDWR | O_APPEND);
lseek(fd1, 10000, SEEK_SET);
write(fd1, "abcdefghij", 10);
write(fd2, "abcdefghij", 10);
fstat(fd1, &buff1);
fstat(fd2, &buff2);
printf(" %d %d", buff1.st_size, buff2.st_size);
return 0;
}

Before running the program, the file 1.txt and 2.txt size is 20 each. What is the output?
a) 30 30
b) 100020 20
c) 100030 30
d) 100010 30

Linux Operating System Management Interview Question
Linux Operating System Management Interview Question

Answer:

d) 100010 30

Download Linux Operating System Management Interview Questions And Answers PDF

Previous QuestionNext Question
Which function can be used instead of the dup2 to duplicate the file descriptor?
a) read()
b) open()
c) stat()
d) fcntl()
Given a code snippet below?

#define PERMS (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)
int main() {
int fd1, fd2;
umask(0);
fd1 = open("file1", O_CREAT | O_RDWR, PERMS)
umask(S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
fd2 = open("file2", O_CREAT | O_RDWR, PERMS)
return 0;
}

The newly created files file1 and file2 will have the permissions respectively
a) rw-rw-rw- r---
b) r--- rw-rw-rw-
c) rw-rw-rw- rw---
d) None of the above