0% found this document useful (0 votes)
69 views6 pages

UNIX System Process Basics

A process is an instance of a running program. A process is created through 3 system calls: fork(), exec(), and wait(). fork() creates a child process, exec() overlays the child process with a new program, and wait() allows the parent process to wait for the child process to complete. When a user logs into a shell, init forks getty processes, which fork login processes, which fork shell processes. The ps command displays information about active processes. Common ps options include -f for full listing, -u to view processes by user, and -A to view all processes. Crontab allows scheduling tasks to run periodically using a crontab file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views6 pages

UNIX System Process Basics

A process is an instance of a running program. A process is created through 3 system calls: fork(), exec(), and wait(). fork() creates a child process, exec() overlays the child process with a new program, and wait() allows the parent process to wait for the child process to complete. When a user logs into a shell, init forks getty processes, which fork login processes, which fork shell processes. The ps command displays information about active processes. Common ps options include -f for full listing, -u to view processes by user, and -A to view all processes. Crontab allows scheduling tasks to run periodically using a crontab file.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MODULE-5 INTRODUCTION TO UNIX SYSTEM PROCESS

UNIT 5
INTRODUCTION TO UNIX SYSTEM

Process Basics:
A process is an instance of running program. A process is said to be born when the program
starts execution and remains alive as long as the program is active. After execution is complete,
the process is said to die. A process also has a name, usually the name of the program being
executed.

Mechanism of Process Creation:


There are 3 distinct phase in mechanism of process creation and uses 3 system calls:

1.fork()

2.exec()

3.wait().
•fork(): Creates a child process. A new process is created because an existing process creates
an exact copy of itself. This child process has the same environment as its parent but only the
PID is different. This procedure is known as forking.
•exec(): After forking the process, the address space of the child process is overwritten by the
new process data. This is done through exec call to the system. No new process is created over
here. The PID & PPID remains unchanged.
•wait(): The parent then executes wait system call to wait for the child process to complete its
execution.

All this means that when you run a command (say, cat) from the shell, the shell first forks
another shell process. The newly forked shell the overlays itself with the executable image of cat.
which then starts to run. The parent (the shell) waits for cat to terminate and then picks up the
exit status of the child. This is a number returned by the child to the kernel, and has great
significance in both shell programming and systems programming.

The important attributes that are inherited by the child process from its parents are: Real UID and
GID, PGID, Nice value, Environment setting, Current working directory, memory segments etc.

Dept of CSE, BrCE 1


MODULE-5 INTRODUCTION TO UNIX SYSTEM PROCESS

The process remembers the directory from where it was run. This attribute acquires importance
when a process also changes the directory.

How the Shell is Created

When the system moved to multiuser mode, init forks and execs a getty for every active
communication line. Each one of the getty prints the login prompt on the respective terminal and
then goes to sleep.

When a user attempts to log in, getty wakes up and forks-execs the login program to verify the
login name and password entered. On successful login, login forks-execs the process representing
the login shell. Repeated overlaying ultimately results in init becoming the immediate ancestor of
the shell as can be seen from this sequence.

init getty login shell

ps command :

ps can be seen as the process counterpart of the file system’s 1s command. The command reads
to through the kernel’s data structures and process tables to fetch the characteristics of processes.

ps Options :

ps is highly variant command; its actual output varies across different UNIX flavours.

(i) Full Listing(-f) :

To get a detailed listing which also shows the parent of every process, use the –f full option:

Dept of CSE, BrCE 2


MODULE-5 INTRODUCTION TO UNIX SYSTEM PROCESS

$ ps -f

(ii) Displaying Processes of User(-u):

It is used to know the activities of any user. The following output shows a user working on the
X window system rather than a character terminal and X running a number of processes on the
user’s behalf:

$ ps –u linuxtechi

(iii) Displaying All user Processes(-a) :

The –a (all) option lists processes of all users but doesn’t display the system processes.

Dept of CSE, BrCE 3


MODULE-5 INTRODUCTION TO UNIX SYSTEM PROCESS

$ ps –a

(iv) All processes (-A):

All processes including user and system processes

$ps-A

Dept of CSE, BrCE 4


MODULE-5 INTRODUCTION TO UNIX SYSTEM PROCESS

Options to ps:

POSIX Option BSD option Significance

-f f full listing showing the PPID of each process

-e or -A aux All processes including user and system processes

-u asr U asr Processes of user usr only

-a Processes of all users excluding processes not


associated with terminal

-l l Long listing showing memory-related information

-t term t term Processes running on terminal


term(say,/dev/console)

Crontab:

Crontab is used to create the crontab file (the list) and later used to change the previously created
crontab file.

If kumar runs the command, a file named kumar will be created in /var/spool/cron/crontabs
containing the contents of cron.txt. In this way different users can have crontab files named after
their user-ids.

Crontab calls up the editor defined in the EDITOR variable(often vi) After editing the command
and quit vi, the commands are automatically schedules for execution.

The contents of the crontab file can be seen with crontab -1 and remove them with crontab –r.

Cron is mainly used by the system administrator to perform housekeeping chores, like removing
outdated files or collecting data on system performance. It’s also extremely useful to periodically
dial up to an internet mail server to send and retrieve mail.

Dept of CSE, BrCE 5


MODULE-5 INTRODUCTION TO UNIX SYSTEM PROCESS

Dept of CSE, BrCE 6

You might also like