Sample VIVA questions on UNIX Programming
What is the difference between UNIX and LINUX?
What is the difference between UNIX and LINUX?
Even though both
UNIX and LINUX are multi user and multi tasking operating systems they are many
differences between them
UNIX
1. UNIX is completely written in C language and developed by
Dennis Ritche.
2. UNIX is not open source. It is fixed to some universities and
companies
3. We cannot extend additional features to UNIX easily.
4. UNIX is a virus free operating system
Examples BSD, System V, Solaris etc
LINUX:
1.Linus is completely written in C language. It is almost similar
to UNIX but not UNIX.
2. LINUX is an open source. i.e., any one can suggest changes or
update any features to LINUX by registering
3. LINUX is virus free operating system
Examples: Red Hat, UBUNTU
Both UNIX and LINUX are virus operating system. i.e.,
even though virus attacks on systems we can easily remove the virus program
file as both are open source software systems
Shells in UNIX:
What is a system call?
In UNIX(LINUX) system there are two types of modes
user mode and kernel mode.
In user mode user mode user programs execute. In Kernel mode the
processor executes in privileged conditions with high security mechanisms. In
kernel mode all system level file are accessed and altered if required.
For every high level system call in user mode there is a
corresponding low level system call in kernel mode.
A system call is a interrupt(or trap) to an operating system when
issued there is change in user mode to kernel mode.
For example in C programming when printf() function is called in
user mode then there is a shift in user mode to kernel mode and in kernel mode
corresponding low level function write() system call is executed. All system
calls in UNIX will execute the code in kernel mode under privileged conditions
Privileged condition are necessary because when a system call is
issued the operating is interacting with system file like files, directories
etc.
The following are various system calls used in UNIX operating
system
1. File
handling system calls:
These system calls ( low level
calls) are used to do operations on files in kernel mode.
open(): This system call is used to open the
file and returns a file pointer
write(): This system call is used to write
some thing to a open'd file
read(): This system call is used to read data
from a open'd file
close(): This system call is used to close the
open's file
dup(): This system call is used to
duplicate the existing file descriptor with new file descriptor value(
the lowest value available)
dup2(): This system call is used to create a
duplicate the existing file descriptor with required value.
link(): There are two types of links. Hard
links and soft links. Both are used to create additional links to existing file
stat(): This system call is used to get the
meta data about file
seek(): This system call is used to move the
cursor location to desired position
ftell(): This system call is used to get the
cursor position
rewind(): This system call is used to move the
cursor position to initial position of a file
2. Directory Handling system
calls:
These system calls are used to do operations
on directories like creating and deleting directories etc.
mkdir(): This system call is used to create new
directory
rmdir(): This system call is used to remove a
existing directory
chdir(): This system call is used to change the
current working directory
pwd(): This system call is used to get the present
working directory
3. Process handling
system calls:
These system
calls are used to do operation on processes like creating a child process and
replacing the process code of a file etc.
fork(): This system call is used to create a
child process
exec(): This system call is used to replace
the process address space with new executable code defined in family of system calls. There are
total 6 system calls
a. execl()
b. execv()
c. execlp()
d. execvp()
e. execve()
f. execvp()
wait(): This system call is used to make the parent process to
wait until child finishes the execution
exit(): This system call is used to exit from process
Signal handling system
calls():
A signal is a message
sent to a operating system by a process. kill() and raise() system calls are
used to send signal to a process. While kill() is used to send a signal to any
process, the raise()
system call is used to send signal to a own process.
alarm(): Signal is raised when alarm time is expired
pause(): This system call is used to pause the present code
executing
Inter Process Communication:
Using IPC we can send and receive data from one process to
another process. IPC can be achieved using pipes, named pipes, message queues,
share memory and semaphores( used for synchronisation).
a. pipes(): http://cjuschools.blogspot.in/search?q=pipes
pipe(): This system call
is used to create a pipe. It returns two file descriptors one for read end and other for write end .
read(): This system call is
used to read the data from the read end of the pipe
write() This system call
is used to write data to the write end of the file
close(): This system call is
used to close the open pipe descriptors
b. Named Pipes(FIFO):
While pipe is a
temporary storage, a named pipe is a permanent storage where we can store data
permanently on hard disk .
mknod() and
mkfifo() are to system calls used to create named pipes.Any process can create
a named pipe and place data on to named pipe. Any process can read data from
the named pipe.
c. Shared memory(): /* ipcs -m */
shmget(): used to create a shared
memory segment
shmat(): used to attach process
address space to shared memory segment
shmctl(): Used to control the shared
memory segment( getting status, deleting etc)
d. message queue: /* ipcs -q */
msgget(): Used to
create message queue
msgsnd(): After
preparing message structure the message is sent using msgsnd() system call
msgrcv(): Used to
receive message
msgctl(): Used to
control the message queue( delete etc)
e. semaphores: used for synchronising. A binary
semaphore is a variable having values 0 and 1 only
A counting semaphore have value greater than
two and can be used by more then two process.
semget():
used to create semaphore set
semctl():
used to control the semaphore set
semop():
used to lock or unlock the shared data or file
Sockets: sockets are used to establish
communication between two devices.
socket(), bind(), listen(), accept(), read(), write() are examples
of socket system calls.
TCP sockets are connection oriented sockets ( establish link and
then send data, reliable)
UDP sockets are connection less sockets. ( send data directly, no
need to establish path, unreliable)
Miscelleneous
All UNIX files
can have read write and execute permissions
chmod(): used to change the file access permissions(
FAP)
chmod 777 file name
root directory in
UNIX is /
Under root /
there are many sub directories like bin, home, etc lib, tmp etc
All users are
present in home directory
All executable
files are located in bin file
pwd is used to
get the present working directory
ls is uses to
list the files in the present working directory
ls –l used to
list the files in long format
mkdir used to
create a new directory
chdir used to
change the present working directory to new directory specified
using vi editor
we write c programs and shell programs
shell program end
with .sh extension
c program ends
with .c extension
gcc or cc command
is a compiler used to compile the c program in UNIX
when compiled the
executable code is loaded into a.out file
to execute a
executable file -- ./a.out ( stand for in root directory a.out is
executable file)
sample lab viva questions, UNIX lab viva questions, LINUX programming lab viva questions, foss lab viva questions viva voice unix quesitons, shells, ./a.out, cc, file handling system calls, directory handling system calls, process handling system calls, difference between fork and vfork system call, socket system calls, TCP sockets and UDP sockets, exec family of system calls. usermode and kernel mode, UNIX programming interview questions,, UNIX expert answers, UNIX certification , how to UNIX certification , UNIX in Five days, simple steps to learn UNIX programming
No comments:
Post a Comment