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.

What Is “ps” Command For?

Answer»

The “ps” commandis used for printing the process status for some or all of the running PROCESSES. The INFORMATION given are the process identification number (PID),the AMOUNT of time that the process has taken to execute so far etc.

The “ps” commandis used for printing the process status for some or all of the running processes. The information given are the process identification number (PID),the amount of time that the process has taken to execute so far etc.

2.

How Can We Get And Set An Environment Variable From A Program?

Answer»
  1. By USINGGETENV()”getting the VALUE of an environment VARIABLE is done.
  2. By using “putenv()”Setting the value of an environment variable is done.

3.

How Do You Check How Much Space Left In Current Drive?

Answer»

By USING “df” command in UNIX we can CHECK how much space LEFT in CURRENT drive.

By using “df” command in UNIX we can check how much space left in current drive.

4.

How Do You Find Which Process Is Taking How Much Cpu?

Answer»

By using “TOPCOMMAND in UNIX we can find process is taking how MUCH CPU.

By using “top” command in UNIX we can find process is taking how much CPU.

5.

How Do You Copy File From One Host To Other?

Answer»

By using “SCPCOMMAND we can copy file from ONE host to other. we can also use rsync command .

By using “scp” command we can copy file from one host to other. we can also use rsync command .

6.

How Do You See Command Line History In Unix?

Answer»

We use HISTORY command ALONG with GREP command in UNIX to find any relevant command we have already EXECUTED.

We use history command along with grep command in unix to find any relevant command we have already executed.

7.

How Do You Know If A Remote Host Is Alive Or Not?

Answer»

We can CHECK these by using either TELNET or PING command in UNIX.

We can check these by using either telnet or ping command in UNIX.

8.

How Will You Run A Process In Background? How Will You Bring That Into Foreground And How Will You Kill That Process?

Answer»

For RUNNING a process in background in command line use “&”. For BRINGING it BACK in foreground command line use “fg jobid” and for getting job id we use command “JOBS”, for KILLING that process find PID and we use kill -9 PID command.

For running a process in background in command line use “&”. For bringing it back in foreground command line use “fg jobid” and for getting job id we use command “jobs”, for killing that process find PID and we use kill -9 PID command.

9.

List The System Calls Used For Process Management:

Answer»
  1. System calls - Description 
  2. fork() - To create a NEW process 
  3. exec() - To execute a new program in a process
  4. wait() - To wait until a CREATED process COMPLETES its execution
  5. exit() - To exit from a process execution
  6. getpid() - To get a process IDENTIFIER of the current process
  7. getppid() - To get parent process identifier
  8. nice() - To bias the existing PRIORITY of a process
  9. brk() - To increase/decrease the data segment size of a process

10.

Predict The Output Of The Following Program Code?<br> Main() <br> { <br> Fork(); Fork(); Fork(); <br> Printf("hello World!"); <br> }

Answer»

"Hello World" will be PRINTED 8 TIMES.

Explanation: 2^n times where n is the NUMBER of CALLS to fork();

"Hello World" will be printed 8 times.

Explanation: 2^n times where n is the number of calls to fork();

11.

Predict The Output Of The Following Program Code.?<br> Main() <br> { <br> Fork(); <br> Printf("hello World!"); <br> }

Answer»

HELLO World!Hello World!

Explanation: The fork creates a child that is a DUPLICATE of the parent PROCESS. The child BEGINS from the fork(). All the statements after the call to fork() will be executed twice.(once by the parent process and other by child). The statement before fork() is executed only by the parent process.

Hello World!Hello World!

Explanation: The fork creates a child that is a duplicate of the parent process. The child begins from the fork(). All the statements after the call to fork() will be executed twice.(once by the parent process and other by child). The statement before fork() is executed only by the parent process.

12.

Explain Fork() System Call.?

Answer»

The 'fork()' USED to create a new process from an EXISTING process. The new process is CALLED the child process, and the existing process is called the parent. We can tell which is which by checking the RETURN value from 'fork()'. The parent gets the child's pid RETURNED to him, but the child gets 0 returned to him.

The 'fork()' used to create a new process from an existing process. The new process is called the child process, and the existing process is called the parent. We can tell which is which by checking the return value from 'fork()'. The parent gets the child's pid returned to him, but the child gets 0 returned to him.

13.

Brief About The Initial Process Sequence While The System Boots Up.?

Answer»

While booting, special process CALLED the 'swapper' or 'scheduler' is created with Process- ID 0. The swapper MANAGES memory allocation for processes and influences CPU allocation.

The swapper INTURN creates 3 CHILDREN:

  1. the process dispatcher,
  2. vhand and
  3. dbflush

with IDs 1,2 and 3 respectively.

This is done by executing the file "/etc/init". Process dispatcher gives birth to the shell. Unix KEEPS track of all the processes in an internal data structure called the Process Table (listing command is ps -el).

While booting, special process called the 'swapper' or 'scheduler' is created with Process- ID 0. The swapper manages memory allocation for processes and influences CPU allocation.

The swapper inturn creates 3 children:

with IDs 1,2 and 3 respectively.

This is done by executing the file "/etc/init". Process dispatcher gives birth to the shell. Unix keeps track of all the processes in an internal data structure called the Process Table (listing command is ps -el).

14.

What Happens When You Execute A Command?

Answer»

When you enter "ls" command to look at the contents of your CURRENT working directory, UNIX does a series of things to create an environment for "ls" and the run it: The shell has UNIX perform a fork. This CREATES a new process that the shell will USE to run the ls program. The shell has UNIX perform an exec of the "ls" program.

This replaces the shell program and data with the program and data for "ls" and then starts running that new program. The "ls" program is loaded into the new process context, replacing the TEXT and data of the shell. The "ls" program performs its task, LISTING the contents of the current directory.

When you enter "ls" command to look at the contents of your current working directory, UNIX does a series of things to create an environment for "ls" and the run it: The shell has UNIX perform a fork. This creates a new process that the shell will use to run the ls program. The shell has UNIX perform an exec of the "ls" program.

This replaces the shell program and data with the program and data for "ls" and then starts running that new program. The "ls" program is loaded into the new process context, replacing the text and data of the shell. The "ls" program performs its task, listing the contents of the current directory.

15.

What Happens When You Execute A Program?

Answer»

When you execute a PROGRAM on your UNIX system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system.

Each process has process context, which is everything that is unique about the state of the program you are currently running. Every time you execute a program the UNIX system does a FORK, which PERFORMS a series of operations to create a process context and then execute your program in that context. 

The steps include the following:

  1. Allocate a slot in the process table, a list of currently running programs kept by UNIX.
  2. Assign a unique process identifier (PID) to the process.
  3. iCopy the context of the parent, the process that requested the spawning of the new process.
  4. Return the new PID to the parent process. This enables the parent process to examine or control the process DIRECTLY.
  5. After the fork is COMPLETE, UNIX runs your program.

When you execute a program on your UNIX system, the system creates a special environment for that program. This environment contains everything needed for the system to run the program as if no other program were running on the system.

Each process has process context, which is everything that is unique about the state of the program you are currently running. Every time you execute a program the UNIX system does a fork, which performs a series of operations to create a process context and then execute your program in that context. 

The steps include the following:

16.

What Is A Zombie?

Answer»

When a program FORKS and the child FINISHES before the PARENT, the kernel still keeps some of its information about the child in case the parent MIGHT need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls 'wait()'; In the interval between the child terminating and the parent calling 'wait()', the child is said to be a 'zombie' (If you do 'ps', the child will have a 'Z' in its status field to indicate this.)

When a program forks and the child finishes before the parent, the kernel still keeps some of its information about the child in case the parent might need it - for example, the parent may need to check the child's exit status. To be able to get this information, the parent calls 'wait()'; In the interval between the child terminating and the parent calling 'wait()', the child is said to be a 'zombie' (If you do 'ps', the child will have a 'Z' in its status field to indicate this.)

17.

How Can A Parent And Child Process Communicate?

Answer»

A parent and child can COMMUNICATE through any of the normal inter-process communication schemes (pipes, sockets, MESSAGE queues, shared memory), but also have some SPECIAL ways to communicate that take ADVANTAGE of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.

A parent and child can communicate through any of the normal inter-process communication schemes (pipes, sockets, message queues, shared memory), but also have some special ways to communicate that take advantage of their relationship as a parent and child. One of the most obvious is that the parent can get the exit status of the child.

18.

How Can You Get/set An Environment Variable From A Program?

Answer»
  1. GETTING the value of an ENVIRONMENT VARIABLE is DONE by using "getenv()". 
  2. Setting the value of an environment variable is done by using "putenv()"

19.

How Would You Kill A Process?

Answer»

The "KILL" COMMAND takes the PID as ONE argument; this identifies which process to terminate. The PID of a process can be got using "ps" command.

The "kill" command takes the PID as one argument; this identifies which process to terminate. The PID of a process can be got using "ps" command.

20.

What Is "ps" Command For?

Answer»

The "ps" COMMAND PRINTS the process STATUS for some or all of the running processes. The information given are the process identification number (PID),the AMOUNT of time that the process has TAKEN to execute so far etc.

The "ps" command prints the process status for some or all of the running processes. The information given are the process identification number (PID),the amount of time that the process has taken to execute so far etc.