Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

1.

Which of the following system call uses file descriptor as an argument?(a) read(b) write(c) close(d) read, write, closeI have been asked this question in quiz.Question is from File Handling System Calls in chapter System Programming I – Files of Unix

Answer»

Right answer is (d) read, write, close

The BEST I can explain: A FILE descriptor is an integer which is allocated when a file is opened. It is used by all system calls that PERFORM some operations on file -LIKE read, write, close, lseek.

2.

System calls and library functions are same.(a) True(b) FalseThis question was addressed to me at a job interview.I'm obligated to ask this question of File Handling System Calls in portion System Programming I – Files of Unix

Answer»

The correct choice is (b) False

Easy EXPLANATION: System calls are built into the kernel, but LIBRARY FUNCTIONS are built on top of them. When a system call is invoked, the pre-processor SWITCHES to kernel mode and returns to the user mode when the call COMPLETES.

3.

For changing the time stamps, _____ system call is invoked.(a) atime(b) utime(c) mtime(d) chI got this question in an online quiz.The doubt is from File Handling System Calls in section System Programming I – Files of Unix

Answer»

Correct option is (b) utime

Easiest explanation: utime SYSTEM call is used to CHANGE a file’s modification and ACCESS TIMES.

4.

chmod and fchmod calls are used for changing file permissions.(a) True(b) FalseThis question was addressed to me in an internship interview.Enquiry is from File Handling System Calls in portion System Programming I – Files of Unix

Answer»

Right answer is (a) True

To explain I would say: chmod and fchmod calls are USED for CHANGING the file PERMISSIONS. Chmod uses pathname for IDENTIFYING a file while fchmod uses the file descriptor.

5.

Both the owner and group owner can be changed by ____ call.(a) chown(b) chgrp(c) chuser(d) chI had been asked this question in class test.This question is from File Handling System Calls in portion System Programming I – Files of Unix

Answer» RIGHT answer is (a) CHOWN

Easy explanation: The chown SYSTEM call is used to CHANGE both the owner and group owner. It has three STATES; chown, fchown, lchown.
6.

Which of the following is used with access call for checking the owner’s permissions?(a) R_OK(b) W_OK(c) X_OK(d) R_OK, W_OK, X_OKThis question was addressed to me in an internship interview.I want to ask this question from File Handling System Calls topic in section System Programming I – Files of Unix

Answer»

Right choice is (d) R_OK, W_OK, X_OK

To explain: By using the ACCESS system call, we can CHECK the FILE’s access RIGHTS. We’ve to specify one of the FOLLOWING four values to define the permission which is needed to be tested.

7.

For checking a file access rights, ___ system call is used.(a) acc(b) access(c) axs(d) filertThis question was posed to me in an interview for internship.My question is from File Handling System Calls in chapter System Programming I – Files of Unix

Answer» CORRECT choice is (B) access

To explain I would SAY: By using the access SYSTEM call, we can check the file’s access rights. It looks at the real UID and real GID of the user running the program and determines that WHETHER the file is accessible by the real user.
8.

Which of the following macro returns true if the file type is a directory?(a) S_ISREG(b) S_ISDIR(c) S_ISCHR(d) S_ISFIFOThis question was addressed to me during an interview.The origin of the question is File Handling System Calls topic in chapter System Programming I – Files of Unix

Answer»

Right option is (B) S_ISDIR

Explanation: The S_ISDIR MACRO RETURNS TRUE if the file type is a directory. The S_ISREG returns true if the file type is REGULAR.

9.

S_IFxxx macros are used for checking the file types.(a) True(b) FalseI have been asked this question in unit test.The question is from File Handling System Calls topic in portion System Programming I – Files of Unix

Answer»

Correct choice is (a) True

The BEST EXPLANATION: All UNIX systems provide a SET of macros beginning with S_IF (often called S_IFxxx macros) that provide us with a function of checking the file type. But modern UNIX system PERFORMS this task in a more simplified manner using S_ISxxx macros.

10.

____ system call is used for renaming a file, directory or symbolic link.(a) renam(b) rename(c) ren(d) changeThis question was addressed to me by my college professor while I was bunking the class.The doubt is from File Handling System Calls topic in division System Programming I – Files of Unix

Answer»

Correct CHOICE is (b) rename

The best I can explain: The rename call is USED for renaming any TYPE of FILE. It can rename a file, a directory or a SYMBOLIC link.

11.

For removing a link, ____ is used.(a) link(b) symlink(c) unlink(d) delinkThe question was asked during an internship interview.This is a very interesting question from File handling System Calls topic in chapter System Programming I – Files of Unix

Answer»

Right choice is (c) unlink

Explanation: The unlink system call removes the directory entry for the FILE (the ARGUMENT) and decrements the LINK count in its INODE by ONE.

12.

For creating a hard and symbolic link, which system calls are used?(a) link, unlink(b) link, symlink(c) unlink, ulink(d) hlink, slinkThe question was asked by my school principal while I was bunking the class.My question is from File handling System Calls in division System Programming I – Files of Unix

Answer»

Correct option is (B) link, symlink

To explain: UNLIKE the ln command which CREATES both hard and symbolic LINKS, the system call library has two separate functions, link and symlink for these tasks.

13.

A super user can use ___ call for creating a directory.(a) mknod(b) mkdr(c) rmdir(d) chdirI got this question during an interview.My question is based upon File handling System Calls topic in portion System Programming I – Files of Unix

Answer»

Right CHOICE is (a) MKNOD

The EXPLANATION is: A superuser can use the mknod system call to create a directory but a NON privileged USER has to use the mkdir call.

14.

Directories can also be opened, read and written in the same way as regular files.(a) True(b) FalseThis question was addressed to me in my homework.This interesting question is from File handling System Calls in section System Programming I – Files of Unix

Answer»

The correct OPTION is (a) True

The EXPLANATION: Directories are also files, and they can also be written, read and opened in the same way as regular files. We can USE open, close and read SYSTEM calls for PERFORMING these tasks.

15.

For creating and removing directories, which of the following system calls are used?(a) mkdir(b) rmdir(c) chdir(d) mkdir and rmdirThis question was addressed to me in a job interview.My enquiry is from File handling System Calls topic in division System Programming I – Files of Unix

Answer»

Correct answer is (d) mkdir and rmdir

The explanation: A NON privileged user uses mkdir and rmdir calls for creating and REMOVING DIRECTORIES respectively.

16.

Which of the following system calls performs the action of cd command?(a) chdir(b) fchdir(c) mkdir(d) chdir and fchdirThis question was addressed to me at a job interview.This interesting question is from File handling System Calls topic in chapter System Programming I – Files of Unix

Answer»

Right option is (d) chdir and fchdir

Explanation: There are two SYSTEM CALLS that PERFORM the action of cd COMMAND. They are chdir and fchdir which uses pathname and a file descriptor RESPECTIVELY as an argument.

17.

The vnode table is also called _____(a) inode table(b) file table(c) vtable(d) vttableThe question was posed to me in quiz.The doubt is from File handling System Calls topic in portion System Programming I – Files of Unix

Answer»

The correct choice is (a) INODE table

The explanation is: The file table contains a POINTER to the vnode table, which is the third table in the scheme. It is also CALLED as inode table. This table contains all the information present in the inode except that this structure is MAINTAINED in MEMORY.

18.

The file table contains _________(a) mode of opening(b) status flags(c) offset pointer, reference count(d) mode of opening, status flags, offset printer and reference countThis question was posed to me in an online interview.Enquiry is from File handling System Calls in section System Programming I – Files of Unix

Answer»

Correct answer is (d) mode of opening, STATUS flags, offset printer and REFERENCE count

Easy EXPLANATION: Every entry in the FILE descriptor table points to a file table. This table contains all the data which is RELEVANT to an opened file.

19.

How many data structures does the kernel maintain in memory that contain information about an open file?(a) 3(b) 2(c) 5(d) 1I had been asked this question in unit test.I need to ask this question from File handling System Calls topic in portion System Programming I – Files of Unix

Answer» RIGHT choice is (a) 3

Easiest explanation: The kernel maintains THREE data structures in memory that contain all INFORMATION about an open FILE that a PROCESS needs to access. These data structures are:

The file descriptor table

The file table

The vnode table
20.

The file descriptor table contains all file descriptors for a process.(a) True(b) FalseI have been asked this question during an interview for a job.Question is from File handling System Calls topic in division System Programming I – Files of Unix

Answer»

Correct choice is (a) True

To EXPLAIN I would SAY: The file DESCRIPTOR table contains all allocated file descriptors for a process. Each ENTRY POINTS to the file table. The file descriptor is stored along with a flag in this table.

21.

Which of the following is not a valid symbolic constant?(a) EPERM(b) ENDENT(c) EIOR(d) EEXISTI have been asked this question in semester exam.I want to ask this question from File handling System Calls in section System Programming I – Files of Unix

Answer»

Right OPTION is (c) EIOR

The best I can explain: EPERM displays not a super user (errno 1), ENDENT displays no such FILE or directory (errno 2), EEXIST displays file exist (errno 17).

22.

What is the symbolic constant for errno 2?(a) EPERM(b) ENDENT(c) EIO(d) EEXISTThis question was addressed to me at a job interview.The origin of the question is File handling System Calls in division System Programming I – Files of Unix

Answer»

Correct choice is (b) ENDENT

To EXPLAIN: The symbolic constant for errno 2 is ENDENT. It DISPLAYS the message “no such file and DIRECTORY”.

23.

What is the significance of errno 13?(a) not a super user(b) no such file and directory(c) permission denied(d) no space left on deviceI got this question by my college professor while I was bunking the class.Enquiry is from File handling System Calls topic in division System Programming I – Files of Unix

Answer»

The correct answer is (B) no such FILE and directory

For explanation: The ERRNO 13 DISPLAYS the message “permission denied”. The SYMBOLIC constant for this errno is EACCES.

24.

perror also uses error number to print the error messages.(a) True(b) FalseThis question was posed to me in examination.This intriguing question originated from File handling System Calls in portion System Programming I – Files of Unix

Answer» CORRECT answer is (b) False

Explanation: There is another library FUNCTION, PERROR which is used for PRINTING the error messages. But perror doesn’t use the errno (error number) as an argument.
25.

Which library function is used for printing error messages?(a) strerror(b) stderror(c) strer(d) ptrerrorThis question was addressed to me during an interview.I need to ask this question from File handling System Calls in section System Programming I – Files of Unix

Answer»

The CORRECT option is (a) strerror

Explanation: The library FUNCTION strerror, USES the error NUMBER as argument and returns a pointer to the STRING representing the error.

26.

truncate needs the ___ of the file as an argument but ftruncate works with _______(a) pathname, file descriptor(b) file descriptor, pathname(c) pathname, pathname(d) file descriptor, file descriptorI got this question in a national level competition.Asked question is from System Calls Basics in section System Programming I – Files of Unix

Answer»

Correct option is (a) pathname, file descriptor

Explanation: The truncate and ftruncate CALLS can truncate a file to any LENGTH. truncate NEEDS the pathname of the file as an argument but ftruncate WORKS with the file descriptor.

27.

Which of the following system call is used for truncating a file?(a) truncate(b) ftruncate(c) trunk(d) truncate and ftruncateI had been asked this question by my school principal while I was bunking the class.My question is taken from System Calls Basics topic in portion System Programming I – Files of Unix

Answer»

Right choice is (d) truncate and ftruncate

The BEST I can explain: The truncate and ftruncate calls can truncate a FILE to any LENGTH. These calls are often used in COMBINATION with lseek to overwrite a certain segment of a file.

28.

Which of the following offset is used with lseek system call to set the offset pointer to the end of the file?(a) SEEK_SET(b) SEEK_END(c) SEEK_CUR(d) SEEK_CRThe question was asked in a national level competition.The query is from System Calls Basics topic in section System Programming I – Files of Unix

Answer»

Correct CHOICE is (b) SEEK_END

The best I can explain: The offset SIGNIFIES the position of the offset pointer which can TAKE one of these three VALUES:

29.

____ system call is used for positioning the offset pointer.(a) read(b) write(c) open(d) lseekThis question was posed to me by my college director while I was bunking the class.This is a very interesting question from System Calls Basics topic in portion System Programming I – Files of Unix

Answer»

Right answer is (d) lseek

The explanation is: The lseek system call MOVES the file OFFSET POINTER to a specified point. It doesn’t do any physical I/O rather it determines the position in the file where the next I/O OPERATION will TAKE place.

30.

write system call returns -1 when ___________(a) if disk fills up while write is in progress(b) when file doesn’t exist(c) if the file size exceeds the system’s limit(d) if disk fills up while write is in progress and if the file size exceedsI had been asked this question in an interview for job.My question comes from System Calls Basics topic in chapter System Programming I – Files of Unix

Answer»

The CORRECT choice is (d) if disk fills up while WRITE is in progress and if the file size EXCEEDS

To explain I would say: write system call RETURNS the number of characters WRITTEN. However, it will return -1 if if disk fills up while write is in progress or if the file size exceeds the system’s limit.

31.

____ system call is used for writing to a file.(a) read(b) write(c) close(d) seekThis question was posed to me in an internship interview.My enquiry is from System Calls Basics topic in section System Programming I – Files of Unix

Answer»

Correct option is (B) write

The explanation is: write system call is required for WRITING to a FILE which has previously been opened with the open system call. write system call RETURNS the number of characters written.

32.

close system call returns ____(a) 0(b) -1(c) 1(d) 0 and -1This question was posed to me in a job interview.Query is from System Calls Basics in chapter System Programming I – Files of Unix

Answer» CORRECT CHOICE is (d) 0 and -1

The best I can explain: The return TYPE of close system CALL is an INTEGER. It either returns 0 if the file is closed successfully or -1 otherwise.
33.

Which of the following system call is used for closing a file?(a) open(b) lseek(c) close(d) writeI have been asked this question in an online interview.The query is from System Calls Basics in portion System Programming I – Files of Unix

Answer»

Correct option is (c) CLOSE

To explain I would say: A PROGRAM automatically closes all open files before TERMINATION, but it’s a GOOD practice to close them explicitly. The close system CALL is used for closing a file.

int close (int fd)

34.

open system call returns the file descriptor as ___(a) int(b) float(c) char(d) doubleI have been asked this question in a national level competition.I need to ask this question from System Calls Basics topic in chapter System Programming I – Files of Unix

Answer»

The correct answer is (c) char

Explanation: OPEN returns the FILE descriptor as an INT. This is the lowest number available for allocation and is used as an ARGUMENT by the other four calls (read, WRITE, close, lseek).

35.

Which of the following mode is used for opening a file in both reading and writing?(a) O_RDONLY(b) O_WRONLY(c) O_RDWR(d) O_WDRThis question was addressed to me in an international level competition.Question is from System Calls Basics in chapter System Programming I – Files of Unix

Answer» CORRECT answer is (c) O_RDWR

The explanation is: There are THREE modes of opening a FILE namely:
36.

Which of the following system call is used for opening or creating a file?(a) read(b) write(c) open(d) closeThe question was posed to me in an interview.I need to ask this question from System Calls Basics topic in portion System Programming I – Files of Unix

Answer»

The correct ANSWER is (C) open

Best explanation: To read or write to a FILE, we first need to open it. For this purpose, open SYSTEM call is USED. Open has two forms ; the first forms assumes that the file already exists and the second form creates the file if it doesn’t.

37.

There are ___ modes of opening a file.(a) 4(b) 3(c) 2(d) 1I got this question during an interview.Enquiry is from System Calls Basics topic in chapter System Programming I – Files of Unix

Answer»

Right option is (b) 3

For EXPLANATION: There are THREE modes of opening a FILE, out of which only one MODE is required to be specified while opening the file. The three modes are, O_RDONLY, O_WRONLY, O_RDWR.

38.

For reading input, which of the following system call is used?(a) write(b) rd(c) read(d) changeI have been asked this question by my college director while I was bunking the class.My question is taken from System Calls Basics in division System Programming I – Files of Unix

Answer»

Correct answer is (c) read

The best explanation: The STANDARD C library offers a set of separate FUNCTIONS to read a block of data. For example, to read a block of data fread is used, for reading a line FGETS is used and for reading a character fgetc is used. All these functions invoke the SYSTEM CALL -read, which is available for reading input.

39.

The chmod command invokes the ____ system call.(a) chmod(b) ch(c) read(d) changeI got this question in an online quiz.Question is from System Calls Basics topic in section System Programming I – Files of Unix

Answer»

Correct option is (a) CHMOD

Explanation: Many commands and system CALLS SHARE the same NAMES. For example, the chmod command invokes the chmod system call.

40.

All UNIX and LINUX systems have one thing in common which is ____(a) set of system calls(b) set of commands(c) set of instructions(d) set of text editorsI have been asked this question during an online exam.My doubt is from System Calls Basics in portion System Programming I – Files of Unix

Answer»

Correct answer is (a) SET of system CALLS

For explanation: As we know that, all UNIX and LINUX SYSTEMS have one THING in common; they use the same set of system calls.

41.

In ____ mode, the kernel runs on behalf of the user.(a) user(b) kernel(c) real(d) allThis question was addressed to me at a job interview.I want to ask this question from System Calls Basics topic in section System Programming I – Files of Unix

Answer» RIGHT option is (b) kernel

The EXPLANATION: Whenever a process invokes a SYSTEM call, the CPU switches from user mode to kernel mode which is a more privileged mode. The kernel mode is also called as supervisor mode. In this mode, the kernel RUNS on BEHALF of the user and has access to any memory location and can execute any machine instruction.
42.

When we execute a C program, CPU runs in ____ mode.(a) user(b) kernel(c) supervisory(d) systemI had been asked this question by my school teacher while I was bunking the class.I would like to ask this question from System Calls Basics topic in portion System Programming I – Files of Unix

Answer»

Correct answer is (a) user

For explanation I would SAY: When we execute a C PROGRAM, the CPU runs in user mode. It remains it this particular mode until a system CALL is invoked.

43.

A system call is a routine built into the kernel and performs a basic function.(a) True(b) FalseThis question was posed to me in an interview for internship.This question is from System Calls Basics in chapter System Programming I – Files of Unix

Answer» CORRECT choice is (a) True

For explanation: All UNIX systems offer around 200 special FUNCTIONS known as system calls. A system call is a routine built into the kernel and performs a very basic function that requires communication with the CPU, memory and devices.