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();
}