Study Questions #2 - Topic 6 + Topic 7, Qn #1-50 Flashcards

1
Q
  1. What is the Unix process?
A

A process (a program that is executing)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
  1. What are the three main states that any living process may have?
A
Running
 For a short slice of time only
 Ready to run
 A ready process means
 it could use the CPU immediately (if it is allowed to do so)
 The scheduler decides which of the ready processes to run next
 Blocked or sleeping
 Waiting for an event to occur,
e.g., I/O or signal
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
  1. Under which condition does a Unix process enter a blocked state?
A

Waiting for an event to occur,

e.g., I/O or signal

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
  1. In Unix, what is the difference between a process ready state and blocked state?
A
Blocked = waiting for event to finish.
Ready = Waiting on the scheduler to decide which process runs next.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
  1. What is the Unix PID?
A

Process ID = Keep track of all processes in the system.

Similar to the idea of inodes in case of files, or S.I.N. in our daily life

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q
  1. What is the Unix PPID?
A

Parent Process ID

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q
  1. In a Unix operating system, scheduling services are performed by a program called scheduler. What are the main tasks that a schedule perform?
A
  • Maintains a list of all the processes waiting to execute
  • Chooses one process at a time, and gives it a chance to run
    for a short time called time slice (typically 10 milliseconds)
  • Saves data related to the interrupted processes so that they can
    be resumed later
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q
  1. List five of the Unix system calls that coordinate processes. Describe the main function of each of them.
A

 fork: creates a copy (child) of the current process (parent)
 exec: changes the program that a process is running
 wait: forces a process to pause until another process finishing its execution
 exit: terminates a process
 chomd: change permissions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q
  1. What are the main differences between internal and external Unix commands?
A

 Internal commands: Interpreted directly by the shell (no need to create a new process)
 External commands: Required the shell to run a separate program (need to create a new
process)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
  1. Explain what will happen when executing a Unix external command.
A

The shell will use fork system call to create
a duplicate of the currently running program
 The duplicate (child process) and the original (parent process)
 proceed from the point of the fork with exactly the same data.
 The only difference is the return value from the fork call.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q
  1. In Unix, what is the relation between child and parent processes?
A

 The duplicate (child process) and the original (parent process)
 proceed from the point of the fork with exactly the same data.
 The only difference is the return value from the fork call.
fork returns
 the child PID to the parent process and
 0 to the child process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
  1. Explain in details what will happen when a process executes the fork system call.
A

Fork is an operation whereby a process creates a copy of itself. It is usually a system call, implemented in the kernel.

  1. Process is duplicated.
  2. Child inherits the properties (descriptors) from the Parent.
  3. The parent and the child share data content (like a pointer).
  4. If a parent process unexpectedly died,
    The child will keep executing,
    The child process is considered to be an orphan
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q
  1. Explain in details what will happen when a process executes the exec system call.
A

exec: changes the program that a process is running *

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q
  1. What is the Unix Zombie state?
A

A zombie process is a process that completed execution but still in process table.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q
  1. When does a Unix process enter a Zombie state?
A

When a process ends, all of the memory and resources associated with it are deallocated so they can be used by other processes. However, the process’s entry in the process table remains. The parent can read the child’s exit status by executing the wait system call, at which stage the zombie is removed
After the zombie is removed, its process ID and entry in the process table can then be reused. However, if a parent fails to call wait, the zombie will be left in the process table. In some situations this may be desirable, for example if the parent creates another child process it ensures that it will not be allocated the same process ID.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q
  1. What is the Unix job?
A

A job refers to all the processes that are necessary to execute an
entire command line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q
  1. In Unix systems, what is the only living ancestor of all other processes in the system? Explain why.
A

In Unix, toward the end of the boot procedure, the kernel
creates a special process by hand without forking
 This process is given a PID of 0 (process#0)
 Process#0 initializes many data structures needed by the kernel
 At the end, it forks process#1 and
then somehow disappeared (terminated itself)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q
  1. In Unix, what is an orphan process?
A

Orphan processes is kind of the opposite situation of zombie processes, since it refers to the case where a parent process terminates before its child processes, in which case these children are said to become “orphaned”.
The child will keep executing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
  1. In Unix, when does a process become an orphan?
A

If a parent process unexpectedly died (before the child)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q
  1. In Unix, who does adopt orphan processes?
A

Process#1 automatically adopts all orphan processes, hence it
 receives the control from the child process when finishing execution
 Informs the kernel to de-allocates the child used resources and kill it

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q
  1. In Unix, why orphan processes need to be adopted?
A

In UNIX all processes must be in a single tree, so orphans must be adopted

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q
  1. In Unix systems, what will happen if a parent process unexpectedly died before its child finishing its process?
A

Child processes are not notified immediately when their parent finishes. Instead, the system simply redefines the “parent-pid” field in the child process’s data to be the process that is the “ancestor” of every other process in the system, whose pid generally has the value 1 (one), and whose name is traditionally “init”.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q
  1. In Unix systems, what are the main differences between a foreground and a background executions of a program?
A

In the foreground
 The shell waits for the command to finish before giving another prompt to
allow you to continue
When running a command in the background
 you do not have to wait for the command to finish before starting another command
 Useful when running a command that needs a long time
 The window will be free so you can use it for other work

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q
  1. List five of the Unix signals that are used with the kill command. Describe the main function of each of them.
A

Name Des Used for

0 SIGNULL Null Check access to pid
1 SIGHUP Hangup Terminate; can be trapped
2 SIGINT Interrupt Terminate; can be trapped
3 SIGQUIT Quit Terminate with core dump; can be
9 SIGKILL Kill Forced termination; cannot be trapped
15 SIGTERM Terminate Terminate; can be traped
24 SIGSTOP Stop Pause the process; cannot be trapped
25 SIGTSTP Terminal stop Pause the process; can be
26 SIGCONT Continue Run a stopped process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q
  1. How similar the Unix stop and kill commands?
A

Kill: Immediate termination (Can not be
trapped or ignored by a process)

Stop (suspend): sent when you press ^Z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q
  1. How similar the Unix ^z and stop command?
A

Stop (suspend): sent when you press ^Z = same cmd

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
  1. How similar the Unix ^z and kill command?
A

Kill: Immediate termination (Can not be
trapped or ignored by a process)

Stop (suspend): sent when you press ^Z

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q
  1. How similar the Unix ^c and kill command?
A

Interrupt: sent when you press ^C

Kill: Immediate termination (Can not be
trapped or ignored by a process)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q
  1. How do you run a Unix job in the background?
A

-bg

JobName -bg

Use Jobs to find active jobs.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q
  1. How do you run a Unix job in the foreground?
A

-fg

JobName -fg

Default runs the program in the foreground.

31
Q
  1. How do you move a Unix job from the foreground to the background?
A

fg

32
Q
  1. How do you move a Unix job from the background to the foreground?
A

bg

33
Q
  1. In a C-shell, what will happen if a background task
    a. sends output to the standard output, or standard error, and you have not redirect them?
    b. requests input from the standard input, and you have not redirected the standard input?
A

a. If a background task sends output to the standard output, or standard
error, and you do not redirect it,
 output appears on the screen, even if you are running another job
b. Bourne-style shells (i.g., sh, bash)
 Supply a null string

34
Q
  1. In a Bourne-shell, what will happen if a background task
    a. sends output to the standard output, or standard error, and have not redirect them?
    b. requests input from the standard input, and you have not redirected the standard input?
A

a. If a background task sends output to the standard output, or standard
error, and you do not redirect it,
 output appears on the screen, even if you are running another job
b. C-style shells (e.g., csh, tcsh)
 Suspend the job and wait for you to give it input

35
Q
  1. Can you start typing the next command before the previous command completed its execution? If yes, how?
A

x

36
Q
  1. How do you display information about the current Unix processes?
A

ps -ef *

37
Q
  1. How do you display information about your current Unix jobs?
A

jobs

38
Q
  1. What is the difference between killing and stopping a Unix process?
A

Kill ends the process. Stop suspends the process.

39
Q
  1. How do you kill a Unix process?
A

kill pid#

40
Q
  1. You started a program named ABC but you realized that it is not behaving and it will take a long time to finish execution. What steps would you take to kill it? If ABC does not respond, what do you do?
A

^c. This will kill the process.

41
Q
  1. How do you stop a Unix process?
A

^z. This will suspend the process.

42
Q
  1. How do you resume a stopped Unix process?
A

It depends on if it is in the fg or bg.

fg job#
bg job#

43
Q
  1. In Unix while a program is running, what does happen when you press ^c?
A

Kills the program

44
Q
  1. In Unix a program is running, what does happen when you press ^z?
A

Suspends the program

45
Q
  1. In Unix, what is the daemon process?
A

Some of these processes are called daemon:
 programs running in the background
 completely disconnected from any terminal

46
Q
  1. Does Unix daemons work in the foreground or in the background?
A

Background

47
Q
  1. In Unix, who is the parent of all daemon processes?
A

the init process (process#1),

48
Q
  1. List eight Unix daemon processes. Describe the main function of each of them.
A

 init: The Unix program which spawns all other processes.
 crond: Time-based job scheduler, runs jobs in the background.
 dhcpd: Dynamically configure TCP/IP information for clients.
 fingerd: Provides a network interface for the finger protocol, as
used by the finger command.
 ftpd: Services FTP requests from a remote system.
 httpd: Web server daemon.
 inetd: Listens for network connection requests.
 lpd: The line printer daemon that manages printer spooling.
 nfsd: Processes NFS operation requests from client systems.

49
Q
  1. When you give a shell more than one command or when you write a shell script, you must separate them. List 5 command separators in Unix. List the characteristics of each one of them.
A

Newline character: Initiates execution of the command proceeding it
‘ ; ‘ character: Does not initiate execution of the command proceeding it
‘ & ‘ character: Does not initiate execution of the command proceeding it. Executes the task in the background
‘ | ‘ character: Does not initiate execution of the command proceeding it. Pipes the output of the command to the left to the input of the command
to the right
‘ ( ) ‘ characters, i.e., parentheses: Does not initiate execution of the command proceeding it. Groups commands (the shell treats each group as one job)

50
Q
  1. Assuming that you are running a Bourne-shell and the abc file does not exist, what is the output of the following Unix
    commands:
    cd /tmp; pwd > abc ; ln abc ABC; rm abc; cat ABC
A

x

51
Q
51. The following is a simple Unix Bourne shell script (program). This program displays the shell script filename ($0), the iteration number ($i) followed by a colon (:), and the date/time of displaying this information. The program will do so three times--one second a part (sleep 1). At the end, it will display a message saying that the program
finished execution.
#!/bin/sh
i=1
while [ $i -le 3 ]; do
echo $0 $i ":" `date`
sleep 1
i=`expr $i + 1`
done
echo $0 ": finished execution."

a. Type in the above script in a file called prog-A
b. Copy prog-A to prog-B and copy prog-A to prog-C
c. Change the permission of prog-A, prog-B, and prog-C file to give execution permission to the user owner.
d. What will be the output if you execute the following commands (below)?
e. Draw a time chart to show when, approximately, each program will start and end.
f. How do you stop each of these programs during its execution?

i. Prog-A; prog-B; prog-C
ii. Prog-A; prog-B; prog-C;
iii. Prog-A; prog-B prog-C
iv. Prog-A; prog-B prog-C;
v. Prog-A prog-B; prog-C
vi. Prog-A prog-B; prog-C;
vii. prog-A prog-B prog-C
viii. prog-A prog-B prog-C;
ix. prog-A& prog-B; prog-C
x. prog-A& prog-B prog-C
xi. prog-A& prog-B& prog-C
xii. prog-A; prog-B& prog-C
xiii. prog-A prog-B& prog-C
xiv. prog-A prog-B& prog-C&
xv. prog-A& prog-B& prog-C&
xvi. prog-A& prog-B prog-C&
xvii. prog-A; (prog-B; prog-C)
xviii. prog-A; (prog-B prog-C)
xix. prog-A; (prog-B& prog-C)
xx. prog-A& (prog-B; prog-C)
xxi. prog-A& (prog-B prog-C)
xxii. prog-A& (prog-B& prog-C)
xxiii. (prog-A& prog-B); prog-C
xxiv. (prog-A; prog-B); prog-C
xxv. (prog-A prog-B); prog-C
xxvi. (prog-A& prog-B)& prog-C
xxvii. (prog-A; prog-B)& prog-C
xxviii. (prog-A prog-B)& prog-C
xxix. Prog-A | prog-B; prog-C
xxx. Prog-A | tee prog-B; prog-C
xxxi. Prog-A | prog-B& prog-C
xxxii. Prog-A | tee prog-B& prog-C
xxxiii. Prog-A | prog-B prog-C
xxxiv. Prog-A | tee prog-B prog-C
xxxv. Prog-A; prog-B | prog-C
xxxvi. Prog-A; prog-B | tee prog-C
xxxvii. prog-A& prog-B | prog-C
xxxviii. prog-A& prog-B | tee prog-C
xxxix. prog-A prog-B | prog-C
xl. prog-A prog-B | tee prog-C
xli. prog-A | prog-B | prog-C
xlii. prog-A | tee prog-B | tee prog-C
xliii. Prog-A | prog-B; prog-C&
Copyright © 2013 Mahmoud El-Sakka
xliv. Prog-A | tee prog-B; prog-C&
xlv. Prog-A | prog-B& prog-C&
xlvi. Prog-A | tee prog-B& prog-C&
xlvii. Prog-A | prog-B prog-C&
xlviii. Prog-A | tee prog-B prog-C&
xlix. Prog-A; prog-B | prog-C&
l. Prog-A; prog-B | tee prog-C&
li. prog-A& prog-B | prog-C&
lii. prog-A& prog-B | tee prog-C&
liii. prog-A prog-B | prog-C&
liv. prog-A prog-B | tee prog-C&
lv. prog-A | tee prog-B | tee prog-C&
lvi. prog-A | prog-B | prog-C&
lvii. prog-A | tee prog-B | tee prog-C&
lviii. prog-A |(prog-B; prog-C)
lix. prog-A | tee (prog-B; prog-C)
lx. prog-A |(prog-B& prog-C)
lxi. prog-A | tee (prog-B& prog-C)
lxii. prog-A |(prog-B prog-C)
lxiii. prog-A | tee (prog-B prog-C)
lxiv. prog-A; (prog-B | prog-C)
lxv. prog-A; (prog-B | tee prog-C)
lxvi. prog-A& (prog-B | prog-C)
lxvii. prog-A& (prog-B | tee prog-C)
lxviii. prog-A (prog-B | prog-C)
lxix. prog-A (prog-B | tee prog-C)
lxx. prog-A |(prog-B | prog-C)
lxxi. prog-A | tee (prog-B | tee prog-C)
lxxii. (prog-A; prog-B)| prog-C
lxxiii. (prog-A; prog-B)| tee prog-C
lxxiv. (prog-A& prog-B)| prog-C
lxxv. (prog-A& prog-B)| tee prog-C
lxxvi. (prog-A prog-B)| prog-C
lxxvii. (prog-A prog-B)| tee prog-C
lxxviii. (prog-A| prog-B); prog-C
lxxix. (prog-A| tee prog-B); prog-C
lxxx. (prog-A| prog-B)& prog-C
lxxxi. (prog-A| tee prog-B)& prog-C
lxxxii. (prog-A| prog-B) prog-C
lxxxiii. (prog-A| tee prog-B) prog-C
lxxxiv. (prog-A| prog-B)| prog-C
lxxxv. (prog-A| tee prog-B)| tee prog-C

A

x

52
Q
52. Predict the output of the following commands:
cd ~
pwd
tcsh
cd /
pwd
exit
pwd
A

x

53
Q
  1. In tcsh shell, how do you create a regular variable?
A

x

54
Q
  1. In sh shell, how do you create a regular variable?
A

x

55
Q
  1. In tcsh shell, how do you change a value of a regular variable?
A

x

56
Q
  1. In sh shell, how do you change a value of a regular variable?
A

x

57
Q
  1. In tcsh shell, how do you delete a regular variable?
A

x

58
Q
  1. In sh shell, how do you delete a regular variable?
A

x

59
Q
  1. In tcsh shell, how do you create an environment variable?
A

x

60
Q
  1. In sh shell, how do you create an environment variable?
A

x

61
Q
  1. In tcsh shell, how do you change a value of an environment variable?
A

x

62
Q
  1. In sh shell, how do you change a value of an environment variable?
A

x

63
Q
  1. In tcsh shell, how do you delete an environment variable?
A

x

64
Q
  1. In sh shell, how do you delete an environment variable?
A

x

65
Q
  1. What is the difference between regular shell variables and environment shell variables?
A

x

66
Q
  1. In tcsh shell, how do you display all current environment variables?
A

x

67
Q
  1. In tcsh shell, how do you display all current regular variables?
A

x

68
Q
  1. In sh shell, how do you display all current environment variables?
A

x

69
Q
  1. In sh shell, how do you display all current regular and environment variables?
A

x

70
Q
  1. Is there a command under sh shell that can display current environment variables alone?
A

x

71
Q
  1. In tcsh shell, create an alias named rm that always deletes files recursively.
A

x

72
Q
  1. In tcsh shell, create an alias named ls that always display files with long format.
A

x

73
Q
  1. In tcsh shell, how would you configure the Unix history to store the last 200 commands?
A

x

74
Q
  1. In tcsh shell, how would you configure the Unix history to store the last 100 commands between two consecutive sessions?
A

x