Essential Objective Questions On Linux Operating
Q – 1 For the below mentioned code:
int main() {
int fd;
fd = open(“logfile”, O_CREAT|O_RDWR, 0600);
lseek(fd, 5, SEEK_CUR);
write(fd, “Hello”, 5);
return 0;
}
What is the logfile size now if it’s initially was 1024 bytes?
a) 5
b) 1024
c) 1029
d) 1034
Ans- b) 1024
Q – 2 Code snippets
str1=”45678n”
str2=”123n”
f1 = fopen(file1,RDWR,RWX)
f2 = dup(f1)
write(f1,str1,len_str1)
write(f2,str2,len_str2)
o/p:
a) 12378
b) 123(newline)8(newline)
c) 123(newline)78(newline)
d) 45678(newline)123(newline)
Ans- d) 45678(newline)123(newline)
Q – 3 Code snippet (file1 size is 2024)
f1 = fopen (file1, RDWR, RWX)
lseek(f1,1024,SEEK_SET)
write(f1,buf,10)
What is offset now.
a) 1024
b) 1034
c) 2034
d) 2054
Ans- b) 1034
Q – 4 Code snippets
str1=”45678n”
str2=”123n”
f1 = fopen(file1,RDWR,RWX)
f2 = fopen(file1,RDWR,RWX)
write(f1,str1,len_str1)
write(f2,str2,len_str2)
o/p:
a) 12378
b) 123(newline)8(newline)
c) 123(newline)78(newline)
d) 45678(newline)123(newline)
Ans- b) 123(newline)8(newline)
Q – 5 What is stored in logfile as per below mentioned code if we execute ./a.out > logfile?
int main() {
int fd;
close(1);
fd = open(“logfile”,O_RDWR, 0744);
write(fd, “Hello”, 5);
printf(“Worldn”);
return 0;
}
a) Hello
b) HelloWorld
c) World
d) None
Ans- b) HelloWorld
Q – 6 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
Ans- c) rw-rw-rw- rw—
Q – 7 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
Ans- d) 100010 30
Q – 8 Which function can be used instead of the dup2 to duplicate the file descriptor?
a) read()
b) open()
c) stat()
d) fcntl()
Ans- d) fcntl()
Q – 9 If one of the thread in multi-threaded process is blocked on an I/O, which of the following is true?
a) The entire process with block if their is no kernel supported threads
b) Other threads of the process will continue to execute even if there is no kernel supported threads
c) It depends on specific implementatation
d) All of the above
Ans- a) The entire process with block if their is no kernel supported threads
Q – 10 If the fork() system call returns -1, then it means?
a) No new child process is created
b) The child process is an orphan
c) The child process is in Zombie
Ans- a) No new child process is created
Q – 11 dup2(1,0):
a) closes the stdout and copies the stdin descriptor to stdout
b) closes the stdin and copies the stdout descriptor to stdin
c) will produce compilation error
d) None of the above
Ans- b) closes the stdin and copies the stdout descriptor to stdin
Q – 12 namei() is:
a) ANSI C library function
b) C library function
c) System call
d) kernel routine
Ans- d) kernel routine
Q – 13 Which system call is used to create a hard link?
a) hard-link
b) link
c) symlink
d) ln
Ans- b) link
Q – 14 read() system call on success returns:
a) 0
b) -1
c) number of character
d) none
Ans- c) number of character
Q – 15 Printf() uses which system call:
a) open
b) read
c) write
d) close
Ans- c) write
Q – 16 The file system information is stored in:
a) Boot block
b) Super Block
c) Inode Table
d) Data Block
Ans- b) Super Block
Q – 17 What is the use of fcntl function?
a) locking a file
b) reading the file descriptor flag
c) changing the file status flag
d) all the above
Ans- d) all the above
Q – 18 Switch table is used by:
a) device special file
b) directory file
c) fifo
d) link file.
Ans- a) device special file
Q – 19 What is the default number of files open per user process?
a) 0
b) 1
c) 2
d) 3
Ans- d) 3
Q – 20 File descriptor table indexes which kernel structure?
a) struct file
b) strruct fs_struct
c) files_struct
d) struct inode
Ans- a) struct file
Q – 21 Each process has unique:
a) fd table
b) file table
c) inode table
d) data block table
Ans- a) fd table
Q – 22 Which one can be a real time schedule policy?
a) SCHED_FIFO
b) SCHED_SPF
c) SCHED_OTHER
d) SCHED_FILO
Ans- a) SCHED_FIFO
Q – 23 Among these files which has an ELF format:
a) shared objects
b) core
c) executables
d) all of the above
Ans- d) all of the above
Q – 24 Describe the use of strace command
Ans- Strace can be used to check the system calls called by the program. So, this can be used for debugging and benchmarking purposes.
Q – 25 On x86-32 Linux, at which address the user stack resides normally?
a) 000000000
b) 0x3fff0000
c) 0x7fff0000
d) 0xbfff0000
Ans- d) 0xbfff0000
Q – 26 Is page table per process entity?
a) Yes
b) No
Ans- a) Yes
Q – 27 Which system call can be used by a user process to lock a memory so that it cannot be swapped out?
Ans- memlock()
Q – 28 Mm_struct maintains?
a) memory files
b) open files
c) pipe
d) active memory regions
Ans- d) active memory regions
Q – 29 LRU stands for:
a) Last received Unit
b) Least recently Used
c) Least recently usable
d) Lost Recoverd unit
Ans- b) Least recently Used
Q – 30 A system has 512MB of physical memory. Which among the following is not a suitable virtual memory size for this system architecture?
a) 512MB
b) 256M
c) 4GB
d) None of the above
Ans- d) None of the above
Q – 31 On x86-32 Linux, at which address the code segment of the program starts?
a) 000000000
b) 008048000
c) 080000000
d) 0xbfff0000
Ans- b) 008048000
Q – 32 Solaris real time class priority is:
a) 0-59
b) 60-99
c) 100-159
d) 160-169
Ans- c) 100-159
Q – 33 Solaris system class priority is:
a) 0-59
b) 60-99
c) 100-159
d) 160-169
Ans- b) 60-99
Q – 34 In Linux kernel-2.6 Real time priority ranges from:
a) 0 to 99
b) 0 to 139
c) -20 to 19
d) 100 to 139
Ans- a) 0 to 99
Q – 35 Nice can be used by an ordinary process to:
a) increase the priority of a process
b) decrease the priority of a process
c) increase or decrease the priority of a process
Ans- b) decrease the priority of a process
Q – 36 Fork returns _____ to parent process on success:
a) 0
b) child process id
c) parent process id
d) none
Ans- b) child process id
Q – 37 The process which terminates before the parent process exits becomes:
a) Zombie
b) Orphan
c) Child
d) None of the above
Ans- a) Zombie
Q – 38 Which niceness value among the following indicate most favorable scheduling?
a) 0
b) 19
c) 5
d) -20
Ans- d) -20
Q – 39 The maximum time slice that can be given to a process in Linux (where tick is 10ms) is:
a) 150ms
b) 10ms
c) 300 ms
d) 600ms
Ans- d) 600ms
Q – 40 What is the output of the below code?
void exit_handler1();
void exit_handler2();
int main() {
int pid;
atexit(exit_handler1);
atexit(exit_handler2);
pid = fork();
if(pid == 0) {
_exit(0);
} else {
sleep(2);
exit(0);
}
return 0;
}
a) Only child executes the exit_handler 1 and 2.
b) Only parent executes the exit_handler 1 and 2.
c) Both parent and child executes the exit_handler 1 and 2.
d) Neither parent nor child executes the exit_handler 1 and 2.
Ans- b) Only parent executes the exit_handler 1 and 2.
Q – 41 What is output of the following program?
int main() {
fork();
fork();
fork();
if (wait(0) == -1)
printf(“leaf childn”);
}
a) “leaf child” will be printed 1 times
b) “leaf child” will be printed 3 times
c) “leaf child” will be printed 4 times
d) “leaf child” will be printed 8 times
Ans- c) “leaf child” will be printed 4 times
Q – 42 How many times printf() will be executed in the below mentioned program?
main() {
int i;
for (i = 0; i < 4; i++)
fork();
printf(“my pid = %dn”, getpid());
}
a) 4
b) 8
c) 16
d) 32
Ans- c) 16
Q – 43 Return value of fork() system call can be:
a) -1,<0,0
b) -1,>0,0
Ans- b) -1,>0,0
Q – 44 Pid of init process:
a) 0
b) 1
c) 32767
d) none of the above
Ans- b) 1
Q – 45 How do you get parent process identification number?
a) waitpid
b) getpid()
c) getppid()
d) parentid()
Ans- c) getppid()
Q – 46 Which of the following files need to be referred for user’s secondary group?
a) /etc/passwd
b) /etc/shadow
c) /etc/group
d) /etc/profile
Ans- c) /etc/group
Q – 47 What is the default maximum number of processes that can exist in Linux?
a) 32768
b) 1024
c) 4096
d) unlimited
Ans- a) 32768
Q – 48 What is a context switch?
a) Kernel switches from executing one process to another.
b) Process switches from kernel mode to user mode.
c) Process switches from user mode to kernel mode.
d) None of the above
Ans- a) Kernel switches from executing one process to another.
Q – 49 Which of the following command can be used to change the user password?
a) User can’t change the password
b) passwd
c) passd
d) pwd
Ans- b) passwd
Q – 50 By default, a Linux user falls under which group?
a) staff
b) others
c) same as userid (UPG)
d) system
Ans- c) same as userid (UPG)
Q – 51 The login shell is:
a) The shell program that runs when the user logs in
b) The shell program that authenticates the user while logging in
c) Common shell for all the users that belong to the same group
d) None of the above
Ans- a) The shell program that runs when the user logs in
Q – 52 What does the following command do?
who | wc -l
a) List the number of users logged in
b) List the users
c) List the number of users in the system
d) Display the content of who command
Ans- a) List the number of users logged in
Q – 53 The /etc/passwd file doesn’t contain:
a) userid
b) home directory for a user
c) login shell name
d) None of the above
Ans- d) None of the above
Q – 54 User id 0 is:
a) An invalid user id
b) The id of the root user
c) The id of a user when the user’s account is deleted
d) None of the above
Ans- b) The id of the root user
Q – 55 The encrypted password of a user is stored in:
a) /etc/shadow
b) /etc/enpasswwd
c) /etc/.passwd
d) /etc/passwd
Ans- a) /etc/shadow
Q – 57 Which of the following identifiers associated with a process decide its privilege level:
a) uid
b) suid
c) euid
d) gid
Ans- c) euid
Q – 58 If a program executing in background attempts to read from STDIN:
a) It is terminated
b) It’s execution is suspended
c) STDIN is made available to it
d) None of the mentioned
Ans- b) It’s execution is suspended
Q – 59 Process information in the current shell can be obtained by using:
a) kill
b) bg
c) fg
d) ps
Ans- d) ps
Q – 60 A user can change the default log-in shell using:
a) chmod
b) chsh
c) rmsh
d) tchsh
Ans- b) chsh
Q – 61 User’s Primary Group id is listed in which file, at the time of creation of the user (On a standard Unix system):
a) /etc/passwd
b) /etc/groups
c) /etc/login
d) /etc/profile
Ans- a) /etc/passwd
Q – 62 Which command is used to bring the background process to forground?
a) bg
b) fg
c) background
d) forground
Ans- b) fg
Q – 63 Which command can be executed by a user who is already logged into the system, in order to change to the root user? (type the command without any parameters)
a) su
b) root
c) chroot
d) user
Ans- a) su
Q – 64 Which signal is sent by the command “kill -9 “?
a) INT
b) TERM
c) KILL
d) STOP
Ans- c) KILL
Q – 65 When a child process exits before the parent process exits, which of the following is true:
a) the child process becomes defunct
b) the parent process becomes defunct
c) if the parent process does not handle SIGCHLD, the child process becomes a zombie
d) none of the above
Ans- b) the parent process becomes defunct
Q – 66 A user issues the following command sequence:
$ a.out &
$ bash
$ a.out &
If the user kills the bash process, then which of the following is true?
a) The second a.out process is also terminated
b) The second a.out process becomes a defunct process
c) The first a.out process becomes a zombie process
d) init process becomes parent of second a.out process
Ans- d) init process becomes parent of second a.out process
Q – 67 ____ is a directory (which should exist), on which to mount the file system?
a) Root
b) Boot
c) Mount-point
d) Partition
Ans- c) Mount-point
Q – 68 Which file system has journaling capability?
a) Ext2
b) Ext4
c) Isofs
d) Procfs
Ans- b) Ext4
Q – 69 Which of the following values for STAT column of ps command is not true:
a) status R means running
b) Status S means sleeping
c) Status E means exited
d) Status Z means zombie
Ans- c) Status E means exited
Q – 70 The signal sent to a process when the Ctrl-C key is pressed is:
a) KILL
b) TSTP
c) TERM
d) INT
Ans- d) INT
Q – 71 We can change the priority of a running process using:
(a) nice
(b) renice
(c) priority cannot be changed for a running process
(d) only superuser can change the priority
Ans- (b) renice
Q – 72 Nohup is used to:
a) automatically hang up the process after logout
b) continue the process after logout
c) create backgroung process
d) manually hang up the process after logout
Ans- b) continue the process after logout
Q – 73 Which file contains the filesystems to be automatically mounted during boot?
a) /etc/mount
b) /etc/fstab
c) /etc/inittab
d) /etc/boot
Ans- b) /etc/fstab
Q – 74 Which filesystem can be used to change certain kernel parameters at runtime using sysctl command?
a) Ext3
b) Sysfs
c) Ext4
d) Procfs
Ans- d) Procfs
Q – 75 Which command is used to mount file system read only?
a) mount -a
b) mount -v
c) mount -f
d) mount -r
Ans- d) mount -r
Q – 76 Filesystem for CDROM is:
a) Ext2
b) Ext3
c) Isofs
d) Procfs
Ans- c) Isofs
Q – 77 Which command is used to check filesystem usage in a system?
a) mount
b) df
c) du
d) dd
Ans- b) df
Q – 78 By default if any regular file is created, the number of link is displayed as 1?
a) True
b) False
Ans- a) True
Q – 79 There are two hard links to the “file1″ say hl and h2 and a softlink sl. What happens if we deleted the “file1″?
a) We will still be able to access the file with hl and h2 but not with sl
b) We will not be able to access the file with hl and h2 but with sl
c) We will be able to access the file with any of hl, h2 and sl
d) We will not be able to access the file with any of hl, h2 and sl
Ans- a) We will still be able to access the file with hl and h2 but not with sl
Q – 80 Which among the following allows fast file system recovery?
a) Ext2
b) Journaling
c) Caching
d) Sysfs
Ans- b) Journaling
Q – 81 How many links are created when we create a directory file?
a) 1
b) 2
c) 3
d) 4
Ans- b) 2
Q – 82 A user creates a link to a file file1 using the following command “ln file1 file2”. Which of the following is not true?
a) file1 and file2 have the same inode numbers
b) The number of links for file1 is displayed as 1
c) The number of links for file1 is displayed as 2
d) The number of links for file2 is displayed as 2
Ans- b) The number of links for file1 is displayed as 1
Q – 83 Deleting a soft-link:
a) Deletes the destination file
b) Deletes both the softlink and the destination file
c) Deletes just the softlink
d) backup of the destination is automatically created
Ans- c) Deletes just the softlink
Q – 84 If two files on same partition point to the same inode structure they are called:
a) Soft links
b) Hard links
c) Alias
d) Special files
Ans- b) Hard links
Q – 85 Which command is used to change permissions of files and directories?
a) mv
b) chgrp
c) chmod
d) set
Ans- c) chmod
Q – 86 Creation of hardlinks that point across partitions:
a) is allowed only to root user
b) Can be done by all users
c) The effects are unspecified
d) is not allowed
Ans- d) is not allowed
Q – 87 Which of the following statement is true?
a) The cp command will preserve the meta data of the file
b) The sort command by default sorts in the numeric order
c) The mv command will preserve the meta data of the file
d) The command ps will display the filesystem usage
Ans- c) The mv command will preserve the meta data of the file
Q – 88 Where can I find the printer in the file structure?
a) /etc
b) /dev
c) /lib
d) /printer
Ans- b) /dev
Q – 89 When mv f1 f2 is executed which file’s inode is freed?
a) f1
b) f2
c) new inode will be used
d) implementation dependent
Ans- b) f2
Q – 90 What UNIX command is used to update the modification time of a file?
a) time
b) modify
c) cat
d) touch
Ans- d) touch
Q – 91 How do you rename file “new” to file “old”?
a) mv new old
b) move new old
c) cp new old
d) rn new old
Ans- a) mv new old
Q – 92 Executing the ‘cd ..’ command when at the root level causes:
a) Error message indicating the user can’t access beyond the root level
b) Behavior is unix-flavor dependent
c) Results in changing to the ‘home’ directory
d) Nothing happens
Ans- d) Nothing happens
Q – 93 Any file’s attribute information is stored in which structure on the disk:
a) Inode
b) Data blocks
c) File blocks
d) Directory file
Ans- a) Inode
Q – 94 What command is used to copy files and directories?
a) copy
b) cp
c) rn
d) cpy
Ans- b) cp
Q – 95 If a file is removed in Unix using ‘rm’ then:
a) The file can be recovered by a normal user
b) The file cannot be recovered by a user
c) The file can be fully recovered provided the sytem is not rebooted
d) The file will be moved to /lost+found directory and can be recovered only by administrator’s intervention
Ans- b) The file cannot be recovered by a user
Q – 96 Which option of rmdir command will remove all directories a, b, c if path is a/b/c:
a) -b
b) -o
c) -p
d) -t
Ans- c) -p
Q – 97 Which command is used to set limits on file size:
a) fsize
b) flimit
c) ulimit
d) usize
Ans- c) ulimit
Q – 98 Which of the following time stamps need not exist for a file on traditional unix file system:
a) Access Time
b) Modification Time
c) Creation Time
d) Change Time
Ans- c) Creation Time