0% found this document useful (0 votes)
22 views

Unix

The document discusses process management system calls in Linux. It explains common system calls like fork(), exec(), exit() and wait() used to manage processes. fork() is used to create a new child process. exec() replaces the process memory space with a new program. exit() terminates the process. wait() suspends a parent process until a child process terminates.

Uploaded by

ffrakesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Unix

The document discusses process management system calls in Linux. It explains common system calls like fork(), exec(), exit() and wait() used to manage processes. fork() is used to create a new child process. exec() replaces the process memory space with a new program. exit() terminates the process. wait() suspends a parent process until a child process terminates.

Uploaded by

ffrakesh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

What are the Process Management System Calls?

System call provides an interface between user program and operating system. When the user wants to
give an instruction to the OS then it will do it through system calls. Or a user program can access the kernel
which is a part of the OS through system calls.
Types of system calls
The different system calls are as follows −
• System calls for Process management
• System calls for File management
• System calls for Directory management
System calls for Process management
A system is used to create a new process or a duplicate process called a fork.
The duplicate process consists of all data in the file description and registers common. The original process
is also called the parent process and the duplicate is called the child process.
The fork call returns a value, which is zero in the child and equal to the child’s PID (Process Identifier) in the
parent. The system calls like exit would request the services for terminating a process.
Loading of programs or changing of the original image with duplicate needs execution of exec. Pid would
help to distinguish between child and parent processes.
Example
Process management system calls in Linux.
• fork − For crea+ng a duplicate process from the parent process.
• wait − Processes are supposed to wait for other processes to complete their work.
• exec − Loads the selected program into the memory.
• exit − Terminates the process.
The pictorial representation of process management system calls is as follows −

fork() − A parent process always uses a fork for crea+ng a new child process. The child process is generally
called a copy of the parent. After execution of fork, both parent and child execute the same program in
separate processes.
exec() − This func+on is used to replace the program executed by a process. The child sometimes may use
exec after a fork for replacing the process memory space with a new program executable making the child
execute a different program than the parent.
exit() − This function is used to terminate the process.
wait() − The parent uses a wait func+on to suspend execu+on +ll a child terminates. Using wait the parent
can obtain the exit status of a terminated child.

Explain the process of booting in Unix.


1. BIOS
BIOS stands for Basic Input/Output System. In simple terms, the BIOS loads and executes the Master Boot
Record (MBR) boot loader.
When you first turn on your computer, the BIOS first performs some integrity checks of the HDD or SSD.
Once the boot loader program is detected, it's then loaded into memory and the BIOS gives control of the
system to it.
2. MBR
MBR stands for Master Boot Record, and is responsible for loading and executing the GRUB boot loader.
3. GRUB
Sometimes called GNU GRUB, which is short for GNU GRand Unified Bootloader, is the typical boot loader
for most modern Linux systems.
The GRUB splash screen is often the first thing you see when you boot your computer.
4. Kernel
The kernel is often referred to as the core of any operating system, Linux included. It has complete control
over everything in your system.
5. Init
At this point, your system executes runlevel programs. At one point it would look for an init file, usually
found at /etc/inittab to decide the Linux run level.
6. Runlevel programs
Depending on which Linux distribution you have installed, you may be able to see different services getting
started.

JavaScript primitive data types


There are five types of primitive data types in JavaScript. They are as follows:

Data Type Description

String represents sequence of characters e.g. "hello"

Number represents numeric values e.g. 100

Boolean represents boolean value either false or true

Undefined represents undefined value

Null represents null i.e. no value at all

JavaScript non-primitive data types

Data Type Description

Object represents instance through which we can access members

Array represents group of similar values


RegExp represents regular expression

Passing Data from One Page to Another in Java Script.


JSP provides different scopes for sharing data objects between pages, requests, and users. The scope
defines how long the object is available and whether it's available only to one user or to all application
users. The following scopes are defined: page, request, session, and application.
Objects placed in the default scope, the page scope, are available only within that page. That's the scope
used in all examples you have seen so far. The request scope is for objects that need to be available to all
pages processing the same request. Objects in the session scope are available to all requests made from
the same browser, and objects in the application scope are shared by all users of the application. According
to the JSP specification, the name used for an object must be unique within all scopes. This means that if
you have an object named userInfo in the application scope, for instance, and save another object with the
same name in the request scope, the container may remove the first object. Few containers (if any)
enforce this rule, but you should ensure you use unique names anyway to avoid portability problems.

#shell script to find sum of n numbers using for loop

echo "Enter Size(N)"


read N

sum=0

echo "Enter Numbers"


for((i=1;i<=N;i++))
do
read num #get number
sum=$((sum + num)) #sum+=num
done

echo $sum

Unix Architecture

Here is a basic block diagram of a Unix system −


The main concept that unites all the versions of Unix is the following four basics −

• Kernel − The kernel is the heart of the opera+ng system. It interacts with the hardware and most of
the tasks like memory management, task scheduling and file management.
• Shell − The shell is the u+lity that processes your requests. When you type in a command at your
terminal, the shell interprets the command and calls the program that you want. The shell uses
standard syntax for all commands. C Shell, Bourne Shell and Korn Shell are the most famous shells
which are available with most of the Unix variants.
• Commands and Utilities − There are various commands and u+li+es which you can make use of in
your day to day activities. cp, mv, cat and grep, etc. are few examples of commands and utilities.
There are over 250 standard commands plus numerous others provided through 3rd party software.
All the commands come along with various options.
• Files and Directories − All the data of Unix is organized into files. All files are then organized into
directories. These directories are further organized into a tree-like structure called the filesystem.

Linux User Management

User management includes everything from creating a user to deleting a user on your system.
useradd

With useradd commands you can add a user.

Syntax:

1. useradd -m -d /home/<userName> -c "<userName>" <userName>

userdel

To delete a user account userdel command is used.

Syntax:

1. userdel -r <userName>
usermod

The command usermod is used to modify the properties of an existing user.

Syntax:

1. usermod -c <'newName'> <oldName>


Deleting Home Directories

By using userdel -r option, you can delete home directory along with user account.

Syntax:

1. userdel -r <userName>

You can change the shell mode with usermod command for a user.
Syntax:

1. usermod -s <newShell> <userName>


chsh

Users can change their login shell with chsh command.

Both the command chsh and chsh -s will work to change the shell.

Syntax:

1. chsh

Starting the vi Editor

The following table lists out the basic commands to use the vi editor −

Sr.No. Command & Description

1 vi filename
Creates a new file if it already does not exist, otherwise opens an existing file.

2 vi -R filename
Opens an existing file in the read-only mode.

3 view filename
Opens an existing file in the read-only mode.

Following is an example to create a new file testfile if it already does not


exist in the current working directory −

$vi testfile

Basic unix commands:


1. who : The ‘$ who’ command displays all the users who have logged into the system
currently. As shown above, on my system I am the only user currently logged in.
$ who
2. pwd : The ‘$pwd’ command stands for ‘print working directory’ and as the name
says,it displays the directory in which we are currently (directory is same as folder
for Windows OS users).
$ pwd
3. mkdir : The ‘$ mkdir’ stands for ‘make directory’ and it creates a new directory.We
have used ‘$ cd’ (which is discussed below) to get into the newly created directory and
again on giving ‘$ pwd’ command,we are displayed with the new ‘newfolder’ directory.
$ mkdir newfolder
4. rmdir : The ‘$ rmdir’ command deletes any directory we want to delete and you can
remember it by its names ‘rmdir’ which stands for ‘remove directory’.
$ rmdir newfolder
5. cd : The ‘$ cd’ command stands for ‘change directory’ and it changes your current
directory to the ‘newfolder’ directory.You can understand this a double-clicking a folder
and then you do some stuff in that folder.
$ cd newfolder (assuming that there is a directory named 'newfolder' on your
system)
6. ls : The ‘ls’ command simply displays the contents of a directory.
$ ls
7. touch : The ‘$ touch’ command creates a file(not directory) and you can simple add an
extension such as .txt after it to make it a Text File.
$ touch example
8. cp : This ‘$ cp ‘ command stands for ‘copy’ and it simply copy/paste the file wherever
you want to.In the above example, we are copying a file ‘file.txt’ from the directory
harssh to a new directory new.
$ cp /home/harssh/file.txt /home/harssh/new/
9. mv : The ‘$ mv’ command stands for ‘move’ and it simply move a file from a directory
to another directory.In the above example a file named ‘file.txt’ is being moved into a
new directory ‘new’
$ mv /home/harssh/file.txt /home/harssh/new
10. rm : The ‘$ rm ‘ command for remove and the ‘-r’ simply recursively deletes file. Try

‘$ rm filename.txt’ at your terminal


$ rm file.txt
11. chmod : The ‘$ chmod’ command stands for change mode command.As there are
many modes in Unix that can be used to manipulate files in the Unix
environment.Basically there are 3 modes that we can use with the ‘chmod’ command
1. +w (stands for write and it changes file permissions to write)
2. +r (stands for read and it changes file permissions to read)
3. +x (generally it is used to make a file executable)
$ chmod +w file.txt
$ chmod +r file.txt
$ chmod +x file.txt
12. cal : The ‘$ cal’ means calendar and it simply display calendar on to your screen.
$ cal
13. file : The ‘$ file’ command displays the type of file.As I mentioned earlier Linux
treats everything as a file so on executing the command file on a directory(Downloads)
it displays directory as the output
$ ls
14. sort : As the name suggests the ‘$ sort’ sorts the contents of the file according to
the ASCII rules.
$ sort file
15. grep : grep is an acronym for ‘globally search a regular expression and print it’.The
‘$ grep’ command searches the specified input fully(globally) for a match with the
supplied pattern and displays it.
In the example, this would search for the word ‘picture’ in the file newsfile and if
found,the lines containing it would be displayed on the screen.
$ grep picture newsfile
16. man : The ‘$ man’ command stands for ‘manual’ and it can display the in-built
manual for most of the commands that we ever need.In the above example, we can read
about the ‘$ pwd’ command.
$ man pwd
17. lpr : The ‘$ lpr’ command send a file to the printer for printing.
$ lpr new.txt
18. passwd : The ‘$ passwd’ command simply changes the password of the user.In
above case ‘harssh’ is the user.
$ passwd
Output: Changing password for harssh.
(current) UNIX password:
19. clear : The ‘$ clear’ command is used to clean up the terminal so that you can type

with more accuracy


$ clear
20. history : The ‘$ history’ command is used to get list of previous commands may be
obtained by executing the following command. you can also use parameters like !n to
re-execute the nth command, !! to executes the most recent command, and !cp this will
execute the most recent command that starts with cp.
$ history

Unix - What is Shells?


The shell provides you with an interface to the UNIX system. It gathers
input from you and executes programs based on that input. When a
program finishes executing, it displays that program's output.

A shell is an environment in which we can run our commands, programs,


and shell scripts.

Shell Prompt:

The prompt, $, which is called command prompt, is issued by the shell.


While the prompt is displayed, you can type a command.
Following is a simple example of date command which displays current date
and time:

$date
Shell Types:

In UNIX there are two major types of shells:

1. The Bourne shell. If you are using a Bourne-type shell, the default
prompt is the $ character.
2. The C shell. If you are using a C-type shell, the default prompt is the
% character.

There are again various subcategories for Bourne Shell which are listed as
follows:

• Bourne shell ( sh)


• Korn shell ( ksh)
• Bourne Again shell ( bash)
• POSIX shell ( sh)

The different C-type shells follow:

• C shell ( csh)
• TENEX/TOPS C shell ( tcsh)
Shell Scripts:

The basic concept of a shell script is a list of commands, which are listed in
the order of execution. A good shell script will have comments, preceded by
a pound sign, #, describing the steps.

Factorial of a number using for loop - Shell Script

#shell script for factorial of a number


#factorial using for loop

echo "Enter a number"


read num

fact=1

for((i=2;i<=num;i++))
{
fact=$((fact * i)) #fact = fact * i
}

echo $fact
Sum of n numbers using for loop- Shell Script

#shell script to find sum of n numbers using for loop

echo "Enter Size(N)"


read N

sum=0

echo "Enter Numbers"


for((i=1;i<=N;i++))
do
read num #get number
sum=$((sum + num)) #sum+=num
done

echo $sum

Largest of n numbers - Shell Script

#shell script for largest of n numbers

echo "Enter Size(N)"


read N

i=1
max=0

echo "Enter Numbers"


while [ $i -le $N ]
do
read num
if [ $i -eq 1 ] #set first number as max
then
max=$num
else #from number 2 update max if the num > max.
if [ $num -gt $max ]
then
max=$num
fi
fi
i=$((i + 1)) #increment i by 1
done

echo $max
Shell program to check the year is the leap year or not

#!/bin/sh

echo "Enter the year"

read year

x=`expr $year % 400`

y=`expr $year % 100`

z=`expr $year % 4`

if [ $x -eq 0 ] || [ $y -ne 0 ] && [ $z –eq 0]

then

echo " Entered year - $year is a leap year"

else

echo "Entered year - $year is not a leap year "

fi

############################

OUTPUT:

$sh year.sh
enter the year
2016
entered year - 2016 is a leap year

$sh year.sh
enter the year
2013
entered year - 2013 is not a leap year
Shell script to check whether a given number is
Armstrong or not
#!/bin/bash
echo "Enter a number: "
read c
x =$c
$c
sum=0
sum
r =0
n =0
while [ $x -gt
gt 0 ]
do
r =`expr $x % 10`
n =`expr $r \* $r \* $r`
sum=`expr
sum $sum + $n`
x =`expr $x / 10`
done
if [ $sum -eq
eq $c ]
then
echo "It is an Armstrong Number."
else
echo "It is not an Armstrong Number."
fi

How can I find the sum of even and odd values in


array in bash script
#!/bin/bash
echo "Enter ten values in the array"
for((n=0;n<10;n++))
do
read array[n];
done
even=0
odd=0

for((i=0;i<10;i++))
do
if($((array[i]%2==0)))
then
$even=array[i]+$even
else
$odd=array[i]+$odd
fi
done

echo"Sum of Even number in the array is $even"

how to check prime number in shell script


#!/bin/bash
echo -e "Enter Number : \c"
read n
for((i=2; i<=$n/2; i++))
do
ans=$(( n%i ))
if [ $ans -eq 0 ]
then
echo "$n is not a prime number."
exit 0
fi
done
echo "$n is a prime number."

You might also like