Top 100+ Unix/linux Interview Questions And Answers
Question 1. How Are Devices Represented In Unix?
Answer :
All gadgets are represented with the aid of files referred to as special documents that are placed in/dev listing. Thus, device documents and different documents are named and accessed inside the identical manner. A 'regular file' is just an ordinary facts document in the disk. A 'block special file' represents a tool with characteristics much like a disk (facts transfer in terms of blocks). A 'character special document' represents a tool with traits similar to a keyboard (records switch is by using flow of bits in sequential order).
Question 2. What Is 'inode'?
Answer :
All UNIX documents have its description saved in a shape known as 'inode'. The inode incorporates data about the report-length, its place, time of remaining access, time of ultimate modification, permission and so on. Directories are also represented as documents and feature an associated inode. In addition to descriptions approximately the document, the inode consists of guidelines to the statistics blocks of the file. If the record is large, inode has indirect pointer to a block of tips to extra statistics blocks (this further aggregates for larger documents). A block is generally 8k.
Inode includes the following fields:
File proprietor identifier
File type
File access permissions
File access instances
Number of links
File length
Location of the report facts
Perl Scripting Interview Questions
Question 3. Brief About The Directory Representation In Unix?
Answer :
A Unix listing is a document containing a correspondence between filenames and inodes. A directory is a special file that the kernel maintains. Only kernel modifies directories, but techniques can study directories. The contents of a listing are a list of filename and inode wide variety pairs. When new directories are created, kernel makes entries named '.' (refers back to the listing itself) and '..' (refers to figure directory).
System name for creating listing is mkdir (pathname, mode).
Question four. What Are The Unix System Calls For I/o?
Answer :
open(pathname,flag,mode) - open record
creat(pathname,mode) - create report
near(filedes) - close an open report
read(filedes,buffer,bytes) - examine statistics from an open report
write(filedes,buffer,bytes) - write records to an open record
lseek(filedes,offset,from) - role an open report
dup(filedes) - duplicate an present record descriptor
dup2(oldfd,newfd) - replica to a preferred report descriptor
fcntl(filedes,cmd,arg) - exchange houses of an open report
ioctl(filedes,request,arg) - exchange the behaviour of an open record
The difference among fcntl anf ioctl is that the former is meant for any open record, at the same time as the latter is for tool-particular operations.
Perl Scripting Tutorial
Question five. How Do You Change File Access Permissions?
Answer :
Every document has following attributes:
owner's consumer ID ( 16 bit integer )
owner's group ID ( sixteen bit integer )
File get entry to mode word
'r w x -r w x- r w x'
(person permission-organization permission-others permission)
r-examine, w-write, x-execute
To alternate the get entry to mode, we use chmod(filename,mode).
Example 1:
To change mode of myfile to 'rw-rw-r–' (ie. Read, write permission for user - examine,write permission for group - only examine permission for others) we give the args as:
chmod(myfile,0664) .
Each operation is represented via discrete values
'r' is four
'w' is 2
'x' is 1
Therefore, for 'rw' the fee is 6(four+2).
Example 2:
To exchange mode of myfile to 'rwxr–r–' we give the args as:
chmod(myfile,0744).
Shell Scripting Interview Questions
Question 6. What Are Links And Symbolic Links In Unix File System?
Answer :
A link is a 2nd call (no longer a document) for a file. Links may be used to assign a couple of name to a report, but can not be used to assign a directory multiple call or hyperlink filenames on one of a kind computer systems.
Symbolic hyperlink 'is' a document that best carries the name of another record.Operation at the symbolic link is directed to the document pointed by using the it.Both the restrictions of links are eliminated in symbolic hyperlinks.
Commands for linking files are:
Link ln filename1 filename2
Symbolic link ln -s filename1 filename2
Question 7. What Is A Fifo?
Answer :
FIFO are in any other case called as 'named pipes'. FIFO (first-in-first-out) is a special record that is said to be records temporary. Once information is study from named pipe, it cannot be read again. Also, facts can be examine simplest inside the order written. It is utilized in interprocess communique where a system writes to 1 end of the pipe (manufacturer) and the opposite reads from the opposite end (purchaser).
Shell Scripting Tutorial Python Interview Questions
Question eight. How Do You Create Special Files Like Named Pipes And Device Files?
Answer :
The system call mknod creates special files inside the following series:
kernel assigns new inode,
Sets the document type to suggest that the file is a pipe, listing or special record,
If it's miles a device report, it makes the alternative entries like predominant, minor tool numbers.
For example:
If the tool is a disk, primary device number refers back to the disk controller and minor device range is the disk.
Question 9. Discuss The Mount And Unmount System Calls?
Answer :
The privileged mount machine name is used to connect a document device to a directory of any other report system; the unmount machine call detaches a document machine. When you mount every other report gadget on to your listing, you are basically splicing one directory tree onto a department in another directory tree. The first argument to mount call is the mount factor, this is , a directory inside the cutting-edge record naming system. The 2nd argument is the document device to mount to that point. When you insert a cdrom to your unix machine's pressure, the file system inside the cdrom automatically mounts to /dev/cdrom in your machine.
Core Java Interview Questions
Question 10. How Does The Inode Map To Data Block Of A File?
Answer :
Inode has 13 block addresses. The first 10 are direct block addresses of the first 10 statistics blocks in the record. The eleventh cope with factors to a one-stage index block. The 12th cope with factors to a -degree (double in-course) index block. The 13th cope with factors to a three-level(triple in-path)index block. This gives a very big maximum file length with efficient get admission to to huge files, but also small files are accessed without delay in a single disk study.
Python Tutorial
Question eleven. What Is A Shell?
Answer :
A shell is an interactive person interface to an working machine offerings that lets in an person to go into commands as character strings or through a graphical user interface. The shell converts them to machine calls to the OS or forks off a procedure to execute the command. System call consequences and different information from the OS are provided to the consumer thru an interactive interface. Commonly used shells are sh,csh,ks etc.
Linux Interview Questions
Question 12. Brief About The Initial Process Sequence While The System Boots Up?
Answer :
While booting, special technique known as the 'swapper' or 'scheduler' is created with Process-ID 0. The swapper manages reminiscence allocation for strategies and impacts CPU allocation.
The swapper inturn creates three children:
the method dispatcher,
vhand and
dbflush
with IDs 1,2 and three respectively.
This is finished by executing the file /etc/init. Process dispatcher gives beginning to the shell. Unix keeps song of all the processes in an internal records structure referred to as the Process Table (list command is ps -el).
Perl Scripting Interview Questions
Question thirteen. What Are Various Ids Associated With A Process?
Answer :
Unix identifies each technique with a completely unique integer called ProcessID. The procedure that executes the request for advent of a procedure is called the 'parent procedure' whose PID is 'Parent Process ID'. Every technique is associated with a specific consumer known as the 'owner' who has privileges over the method. The identification for the person is 'UserID'. Owner is the user who executes the procedure. Process additionally has 'Effective User ID' which determines the get admission to privileges for having access to sources like documents.
Getpid() -technique identity
getppid() -figure procedure identity
getuid() -user id
geteuid() -powerful consumer id
Core Java Tutorial
Question 14. Explain Fork() System Call?
Answer :
The `fork()' used to create a brand new process from an present process. The new process is known as the child system, and the prevailing process is referred to as the parent. We can tell that's which with the aid of checking the return price from `fork()'. The figure receives the child's pid back to him, but the child gets zero again to him.
Question 15. Predict The Output Of The Following Program Code
Main(),
Fork();
Printf("hey World!");
Answer :
Hello World!Hello World!
Explanation:
The fork creates a infant that may be a duplicate of the figure process. The toddler begins from the fork().All the statements after the call to fork() could be completed twice.(as soon as by means of the discern system and different by means of baby). The assertion before fork() is performed only by way of the parent procedure.
Linux Embedded structures Interview Questions
Question 16. Predict The Output Of The Following Program Code
Main()
Fork(); Fork(); Fork();
Printf("hiya World!");
Answer :
"Hello World" may be published 8 instances.
Explanation:
2^n times in which n is the quantity of calls to fork()
Linux Tutorial
Question 17. List The System Calls Used For Process Management?
Answer :
System calls Description:
fork() To create a brand new technique
exec() To execute a new program in a manner
wait() To wait until a created method completes its execution
go out() To go out from a technique execution
getpid() To get a technique identifier of the present day manner
getppid() To get figure process identifier
quality() To bias the existing precedence of a technique
brk() To growth/lower the records phase length of a process.
Red Hat Linux System Administration Interview Questions
Question 18. How Can You Get/set An Environment Variable From A Program?
Answer :
Getting the cost of an environment variable is accomplished by way of using `getenv()'. Setting the price of an environment variable is done by means of the usage of `putenv()'.
Shell Scripting Interview Questions
Question 19. How Can A Parent And Child Process Communicate?
Answer :
A discern and infant can communicate thru any of the ordinary inter-manner verbal exchange schemes (pipes, sockets, message queues, shared reminiscence), but also have a few special methods to talk that take gain of their dating as a figure and child. One of the maximum apparent is that the determine can get the exit repute of the child.
Linux Embedded structures Tutorial
Question 20. What Is A Zombie?
Answer :
When a program forks and the kid finishes before the figure, the kernel nonetheless keeps some of its facts approximately the child in case the discern would possibly need it - for example, the discern may additionally want to test the kid's go out reputation. To be able to get this facts, the figure calls `wait()'; In the c language among the child terminating and the figure calling `wait()', the child is said to be a `zombie' (If you do `playstation ', the kid can have a `Z' in its fame field to indicate this.)
IBM AIX Interview Questions
Question 21. What Are The Process States In Unix?
Answer :
As a manner executes it adjustments state in keeping with its circumstances. Unix approaches have the subsequent states:
Running : The process is either running or it is prepared to run .
Waiting : The system is looking forward to an event or for a resource.
Stopped : The procedure has been stopped, typically by receiving a signal.
Zombie : The manner is lifeless however have not been eliminated from the procedure table.

