Linux Interviews

From Network Security Wiki
Jump to navigation Jump to search

Basics

  • OOM Killer
  • Page Fault
A page fault (sometimes called #PF, PF or hard fault) is a type of exception raised by computer hardware when a running program accesses a memory page that is not currently mapped by the memory management unit (MMU) into the virtual address space of a process.
  • Swap Memory


  • What are Inode and Process ID?
inode is the unique name given by the operating system to each file (ls -i)
process id is the unique id given to each process.
  • What are the process states in Linux?
Ready: The process is created and is ready to run
Running: The process is being executed
Blocked or wait: Process is waiting for input from the user
Terminated or Completed: Process completed execution, or was terminated by the Operating System
Zombie: Process terminated, but the information still exists in the process table.
  • Explain Process Management System Calls in Linux

System Calls to manage the process:

fork () : Used to create a new process
exec() : Execute a new program
wait() : Wait until the process finishes execution
exit() : Exit from the process

System Calls used to get Process ID:

   getpid() : get the unique process id of the process
   getppid() : get the parent process unique id
  • Schedule:
Cron
<minute> <hour> <day> <month> <weekday> <command>

To run a command at 4 pm every Sunday:

0 16 * * 0 <command>
at
echo "shutdown now" | at -m 18:00
  • Find out Shell being used:
echo $SHELL
  • Export Command used to set and reload the environment variables:
export JAVA_HOME = /home/user/Java/bin

Google

  • What happens when I type "ps" into a UNIX prompt?
You basically answered what happens when you turn your computer on with: "The picture appears on the monitor".
A proper answer involves: shell word splitting, searching PATH, loading dynamic libs, argument parsing, syscalls, /proc.
  • Describe exactly what happens when you type 'telnet google.com 80' at a bash prompt, including shell interpretation, network connections.
Prepare to know extensively what happens at the bash layer, including the full process of shell interpretation (variables, parameter expansion).
You should know how a TCP/IP connection is set up and how a webserver responds.
  • What does fseek() command in Linux/Unix do>
fgetpos, fseek, fsetpos, ftell, rewind - reposition a stream
#include <stdio.h>
int fseek(FILE *stream, long offset, int whence);
long ftell(FILE *stream);
void rewind(FILE *stream);
int fgetpos(FILE *stream, fpos_t *pos);
int fsetpos(FILE *stream, const fpos_t *pos);
The fseek() function sets the file position indicator for the stream pointed to by stream. 
The new position, measured in bytes, is obtained by adding offset bytes to the position specified by whence.
If whence is set to SEEK_SET, SEEK_CUR, or SEEK_END, the offset is relative to the start of the file, the current position indicator, or end-of-file, respectively.  
A successful call to the fseek() function clears the end-of-file indicator for the stream and undoes any effects of the ungetc(3) function on the same stream.
The ftell() function obtains the current value of the file position indicator for the stream pointed to by stream.
The rewind() function sets the file position indicator for the stream pointed to by stream to the beginning of the file. 
It is equivalent to:
  (void) fseek(stream, 0L, SEEK_SET)
except that the error indicator for the stream is also cleared (see clearerr(3)).
The fgetpos() and fsetpos() functions are alternate interfaces equivalent to ftell() and fseek() (with whence set to SEEK_SET),
setting and storing the current value of the file offset into or from the object referenced by pos.
On some non-UNIX systems, an fpos_t object may be a complex object and these routines may be the only way to portably reposition a text stream.

Sudo cmd

aman@aman-server:~/scripts$ sudo su -
root@aman-server:~# 

aman@aman-server:~/scripts$ sudo su
root@aman-server:/home/aman/scripts#