250+ TOP MCQs on Process Status:ps Command and Phases of a Process

Unix Multiple Choice Questions on “Process Status:ps Command and Phases of a Process”.

1. Which command shows some attributes of a process?
a) pid
b) $$
c) ps
d) HOME

Answer: c
Clarification: ps command is used to show some attributes of a process. This command reads through the kernel’s data structures and process tables to fetch the characteristics of a process. By default, ps command displays the processes owned by the user running the command.

2. Which of the following attribute is not shown by ps command?
a) PID
b) PPID
c) tty
d) size

Answer: d
Clarification: ps command displays the processes owned by the user running the command. If we execute the command immediately after logging in, it may produce an output like this:

$ ps
PID    TTY        TIME    CMD
291    console     0:00     bash        // login shell of this user

3. Which option is used by ps command to get a detailed listing of process attributes?
a) -u
b) -f
c) -l
d) -x

Answer: b
Clarification: ps is a highly variant command; its actual output varies across different flavours. To get a detailed listing of process attributes along with PPID and owner (UID), we have to use the -f option with ps command. For example,

$ ps  -f
UID    PID    PPID    C    STIME        TTY        TIME    CMD
Abd    367    291    0    12:35:16    console      0:00     vi create_user.sh
Ryan    291    1    0    10:24:58     console      0:00    -bash

4. Which option is used by the system administrator for displaying processes of a user?
a) -f
b) -u
c) -a
d) -e

Answer: b
Clarification: The system administrator needs to use the -u (user) option to know the activities of a user. For example,

$ ps  -u
PID    TTY    TIME    CMD
378?    0:05      Xsession
339    pts/3    0:00    bash
460    pts/5    0:00    dtsession
478    pts/5    0:00    vi

5. The -a option when used with ps command lists processes of all users but doesn’t display the system processes.
a) True
b) False

Answer: a
Clarification: The -a (all) option lists processes of all users but doesn’t display the system processes. For example,

PID     TTY      TIME     CMD
339     pts/3    0:00    bash
460     pts/5    0:00    dtsession
478     pts/5    0:00    vi
1005    pts/1    0:00    ksh
1058    pts/2    0:00    bash

6. Which option is used with ps command to list system processes?
a) -A
b) -a
c) -e
d) –A and -e

Answer: d
Clarification: Apart from processes a user generates, a number of system processes keep running all the time. Most of them are not associated with any terminal. To list all process on our machine, we can use either -A or -e option with ps command. But beware, this list could be very long on a busy system.

7. What will the output of the following command?

a) processes running on terminal named console
b) undefined output
c) erroneous
d) processes running on the current terminal

Answer: a
Clarification: -t is used with ps command along with the terminal name for displaying processes running on the terminal defined in the command.

8. There are ___ distinct phases of a process.
a) 2
b) 5
c) 4
d) 3

Answer: d
Clarification: There are three distinct phases of a process which uses three different system calls or functions. A process can be in its initial state when it is created, after that, the process is in execution state when the instructions of a process are being executed. The third phase of a process is waiting for state when the process is waiting for some action to be taken.

9. A system call is a programmatic way in which the program requests for the service from the kernel of an operating system.
a) True
b) False

Answer: a
Clarification: A system call often referred to as kernel call, is a request from a computer program for the services of the operating system. Basically, to access the resources or to utilize the services of the operating system, system calls are used by computer programs.

10. Which of the following system call is used for creating a new process?
a) read
b) fork
c) wait
d) new

Answer: b
Clarification: A process in UNIX is created using fork() system call. It creates an exact copy of the process that invokes it. Now there will be two processes, one parent process and one child process. The process which invokes the fork system call is called parent process and the new process created is called child process.

11. When fork() is invoked, the child process created gets a new PID.
a) True
b) False

Answer: a
Clarification: The process created using fork is practically identical to that of calling process except for a few parameters like PID. When a process is forked in this manner, the child process gets a new PID.

12. What is the value returned by fork system call, when the creation of child process is unsuccessful?
a) positive integer
b) negative integer
c) zero
d) fractional value

Answer: b
Clarification: fork() system call is used in UNIX for creating new processes. It takes no parameters and returns an integer value. The value returned depends on the following cases:
Positive value: returned to the parent process. The value contains PID of child process which is created.
Negative value: returned if the creation of child process is unsuccessful.
Zero: returned to the newly created child process.

13. Which system call is used to run a new program?
a) fork
b) wait
c) exec
d) exit

Answer: c
Clarification: Forking creates a new process but it is not enough to run a new program. To do so, the forked child needs to overwrite its own images with the code and data of the new program. This mechanism is called exec and the child process is said to exec a new program.

14. Which system call is used by the parent process to wait for the child process to complete?
a) wait
b) exec
c) fork
d) exit

Answer: b
Clarification: The parent process executes the wait() system call to wait for the child process to complete. It picks up the exit status of the child and then continues with its other functions.

Leave a Reply

Your email address will not be published. Required fields are marked *