Showing posts with label UNIX Theory. Show all posts
Showing posts with label UNIX Theory. Show all posts

Wednesday, 31 December 2014

Process and Process management in UNIX

Process and Process management: 




Some library functions works for OS and some other works for specific purpose.

 API---Application Programming Interface(taking help of library)
 SCI--- System call interface
 .dll file of one OS can’t be accessible by another OS.

 fread--- is a function used to read binary data and store in memory based on requirement.

 Syntax:
int fread(int,void *,int);


Manual page:    


#man fread  

fgets---only read characters.



To view system call: 
 #man then press enter 

 Ex:
 #man cal    ----- to view calendar.





In order to communicate with OS we need system calls. fread &read are used for same purpose.
But fread has some limitations compared to read. To view the limitations of read over fread see the following manual pages

#man read
#man fread

What are the differences between programs,application and process? 
 Source code is called as program.
Multiple source codes or object files combination will give us single application.
These all source codes doesn’t occupy different memory locations.
 The combination of all source codes will give us one executable. For that executable file only memory will be created. That executable is called as process.
Running instance of an application is called as process.

What is CPU scheduling or process scheduling?


#include<stdio.h>
main()
{
printf(“executing…”);
while(1)
}

If we run this program in two terminals, both are in running mode.
 P1,P2 be the two processes corresponding to terminal 1, terminal 2.
 P1,P2 demands the CPU simultaneously. One CPU is only the resource for multiple processes.
 Here CPU manages both the processes. This is called “CPU scheduling or process scheduling”.
Here process 1, process2 executables located at different memory locations.

 Define process management?
 Managing CPU for multiple processes efficiently is called process management. 

Define multi-tasking? 
Demanding CPU for multiple processes simultaneously is called multi-tasking.

What is life of process? 
Program execution comes into life when the program loaded from secondary memory to primary memory. And after execution of program, the memory will be released from primary memory.

#ps    ----to view currently running processes


Every process having it’s own(unique) process id’s.
Process id of a particular process changes for every execution. Which is not fixed.

Bash---- one of the process running for longer time.(bourne Against Shell)

#bash ..... to display command prompt
#cal

Here bash takes calendar as input. This command is accepted. It is being executed. 
Then the process is terminated and looks for another input command.

Bash: 
process life is so long. Hence, each and every time cursor waits for input.
For some of the processes, the life time is more. For some of the processes life time is less.
Based on the nature of the job, process life will be decided.

#date --- to display date
Here life of process is shorter.

 Example:Long job

main()
{
printf(“executing…”);
while(1)
}
In this example, life of process is infinite.

 How to display process ID?

main()
{
printf(“process:%d\n”,getpid());
}

We can save this program as p1.c

getpid()----to display process ID

#./p1    (to view output ID)

How to put process in waiting mode?


main()
{
char ch;
Printf(“process:%d\n”,getpid());
ch=getchar();
}
Read More

Monday, 29 December 2014

Overview of UNIX system

who invented UNIX system?

UNIX system was first described in 1974 by ken Thompson and Dennis Ritchie.
Thompson and Ritchie implemented the UNIX On PDP-7 computer and later on PDP-11
( 1971 )
In 1973 the UNIX was written in C programming language.

Architecture of UNIX System

What are inputs and outputs of UNIX system?
Each and Every file has its own file descriptor. file descriptor contains the information related to weather we are reading data from file or writing data to the file.

              1.Input and output uses file descriptors.
              2.Small non-negative integers .
              3.All shells open three descriptors
        a.standard input(stdin: default return value is 0) 
     b.standard output(stdout: default return value is 1) 
      c.standard error(stderr: error number will be returned)

What is meant by Program?

Collection of instructions and data in a file is called program. 
File contents are arranged according To the rules established by kernel. 
After compiling program, we will get an object file. This object file resides on the hard disk. 
List of instructions read from memory and executed by kernel. 

Explain the need of process in UNIX Operating System?
An executing instance of a program is called process. 
Kernel creates a new process.
environment in which program executes is also called as process.
Creation of new process is done By issuing a system call.
The program is used to initialize Instructions and User data.

Process system data includes the following attributes
 Current directory.
Open files.
Descriptors.
Accumulated CPU time…
A process cannot access/ modify The system data directly.

Process ID and Process Groups
Every process has a process ID.
Guaranteed to have unique positive integer.
All processes have a parent
Related processes can be organized into process groups.
One group member is the group leader.
Each member has the process-group-ID.
A process group can have a control terminal
When group leader terminates, All process with the same control terminal are sent hangup signal.
Process ID        Uniquely identifies a process.
Parent-process ID      Process -ID of the process’s parent
Process group ID        Process ID of the group leader
Permissions in UNIX.
positive integers associated with user’s login name Called Real user ID,Real group ID.
Two ID’s associated with a process are effective user ID and effective group ID.
Error Handling in UNIX.
Most Unix system calls return Negative value on error.
The global variable errno Is set to a value for more information.
The file  < errno.h >  defines the variable errno.
The value of errno is not cleared,if an error does not occur.
The value of error is never set to 0 (zero).
Two functions to print error message
strerror( )
perror( ).
System Calls in UNIX Called service points for kernel service.
The system calls are one feature of UNIX That cannot change.
Unix version 7 has  50 system calls.
4.4 BSD  has 110system calls.
SVR4 has  120 system calls.

Header files of UNIX:
1)dirent.h   is for Directory entries
2)errno.h  is for Error codes
3)fcntl.h  is for File control
4)signal.h  is for Signals
5) stddef.h  is for  Standard definitions
6) stdio.h    is for Standard I/O 
7) string.h    is for string operations
8) time.h   is for time and date

Headers for IPC
9) sys/ipc.h  is for  IPC
10) sys/msg.h  is for  Message Queues
11) sys/sem.h  is for  Semaphores
12) sys/shm.h   is for Shared memory
13)sys/stat.h   is for file status
14)sys/times.h   is for Process times
15)sys/types.h  is for   Primitive system data types
16)sys/wait h   is for Process Control

What are the features of UNIX OS(operating system)?

1.Simple user interface.
2.Hierarchical file system.
3.Simple, Consistent interface to devices.
4.Protection of file data.
5.Peripheral devices treated as files.








Read More