The process of summarizing the operating system

Source: Internet
Author: User
Tags stub terminates

This semester learned the door operating system, see everyone after class feel very difficult, so want to organize some things to help you summarize.

Process: A program in execution
Formerly: Single Process
Now: Multiple processes that are multiplexed through the CPU allow multiple processes to execute simultaneously.

Processes are divided into user processes and system processes.
Before the process, the job was actually the first one to be raised and used in a batch system.
Batch System terminology: submitting jobs.
Time-Sharing Terminology: Tasks.
Tasks and jobs are similar to processes. Just a different name.

The process includes a lot of things in memory where a process has text segments (where the code is placed), data (put global variables), heaps (dynamically allocated data, heap is stretched upward), stacks (local variables, function parameters, stacks are stretched downward).
Process and Program differences: The program (EXE), the process is active that contains the PC. When the program is load into the memory, it becomes a process.
When multiple processes are related to a program, they are separate processes, shared text segments, stacks, heaps, and so on.

The process is imagined as a picture in the OS state, new, running, ready, waiting, terminate.

The waiting state means that the process is going to perform I/O and is called into the I/O device waiting queue.

Ready is in an in-memory ready queue.
But remember that a processor can only running a single process, but can have multiple processes in the wait and ready queue.

Ready Queue Listen to the name is very image, don't say much. To say is that he is in memory.
Each device has a team of device columns, linked list storage.
Processes exist in the OS in the form of a PCB.
Then the structure of the PCB, PCB is very complex, but can achieve a lot of functions, do not have to memorize all.
(0) PID

(1) Process status.
(2) PC. Point to the next PCB.
(3) CPU registers. Holds the variable, the stack pointer.
(4) CPU dispatch information. PCB priority, scheduling pointers.
(5) Memory Management information: Base&limit Register, page Table section table.
(6) Bookkeeping information. The time spent, how much memory was used, and so on.
(7) I/O state. Corresponds to the status of the I/O device. The open file.

Multiprogramming the most valuable CPU time by using a program to perform the execution of a program.
Timesharing by dividing a CPU time into a time slice, averaging it to the user, interacting with the user, making the user feel like a person using the machine alone.

Linux is the struct of C to achieve the PCB.

There may be 4 scenarios when a process goes into the CPU:

1.I/O request to enter the device queue.

2. The child process is generated and enters the ready queue.

3. The interruption was forced to cease.

4. Successful execution.

In a batch system, the process is put into the disk's buffer pool, and when it needs to be used, the memory is imported, which becomes the long-term scheduler. Can control the degree of multiple programs (you want to Oh, the multi-channel program is characterized by importing multiple processes at a time into memory, the purpose is to fill the CPU. )
The process of selecting processes from memory to import the CPU is called a short-term scheduler, frequently executed.

Process is divided into: I/O mainly (most PCB are in the device queue), CPU-oriented (most of the PCB for the implementation of calculations). Long-term scheduling needs to choose a reasonable combination into memory.
Unix/windows has no long-term scheduler. Directly put the process into memory, but there will be a disaster, so the introduction of Medium-term schedular.
time-sharing system, the introduction of the medium-term scheduler: Some processes can be removed from memory, to some time can be imported, from the interrupt to continue execution, this also known as swapping.

Context switching: Is the maintenance and recovery of the PCB. Save the old process of the PCB and put it into the new process.
If it is a set of multiple sets of registers, you can save the state of a process with some registers, then the context switch can simply change the pointer of the register.

Process Tree: A process can create new processes while executing, and new processes can create new processes, forming a process tree.
PID is used to identify each process.
The child process can share resources from the parent process or from the OS. However, shared parent process resources can limit the allocation of resources.
The parent process and the child process can execute concurrently or execute the child process before executing the parent process.

In Unix
(1) fork () creates the process, returns 0 when the child processes call, and the parent process returns the PID of the subprocess.
(2) EXEC (): execution.
(3) Wait (): The parent process waits.
(4) Exit (): Exit.

After the process executes exit (), it terminates and frees resources.

When the child process terminates, the PID is returned to the parent process, and the parent process knows which child process is over. The parent process can also terminate the child process through a system call.

Cascade Termination: The parent process terminates causing the child process to terminate.

The process is divided into independent and collaborative. The collaboration process is mentioned when the process is synchronized later.

Process Communication IPC
1. Shared memory. The transfer is fast, using system calls only when creating shared areas, and the rest of the time is normal memory access.

2. Message delivery. Used to exchange less data. Send and receive messages by sending and receiving so that you do not have to share memory.
Neither of the data formats are strictly defined.

Limited buffering: The size of the buffer is fixed.

Infinite buffering: The size of the buffer is infinite.

Shared memory is used to solve the problem of producer consumer model, need to loop queue buffer, add variable count to solve the problem of buffer number only buffer_size-1.
Server code:
while (true)
{
while ((in+1)%buffer_size==out);
Buffer[in]=new;
In= (in+1)%buffer_size;

}
Client code:
while (true)
{
while (in==out);
New=buffer[out];
out= (out+1)%buffer_size;
}

messaging, with OS provided, in a distributed environment.
If you want to enable two processes to deliver messages, you must have a communication line.
Direct communication: The parameters of send and receive directly describe the recipient and sender's object name, and as long as the function is invoked, the link is created automatically, and a line can have only two processes.
Indirect communication: Staging by a third party (mailbox). There can be more than one line between two processes (that is, multiple mailboxes). A mailbox can have multiple process shares. Mailboxes are quite like shared memory.
For send and receive execution methods (in the face of ambiguity), the algorithm is implemented with no specific requirements.

The owner of the mailbox:

1. The process. To determine the owner and the consumer. The mailbox exists in the address space of the process, and the mailbox terminates when the process terminates.
2.OS. is not part of a particular process. The process by which the new mailbox is created defaults to the owner of the mailbox.

Block a feature: a function can no longer perform the function once it is executed.
Non-blocking a function: instead.

Message Passing Buffer queue: 1.0 capacity. 2. Limited. 3. Unlimited.

/*------------------------------------------------------------------------------------------------------------- --

In the definition of communication, have you ever thought of even knowing the object, but how to determine the line, and finally found the target?
Naming problems are also more important.
1.broadcasting
2.forward pointer multi-level search
3.home-based approach
(1) one-tiered scheme: Every search goes through the home camp.
(2) two-tiered scheme: Look for it locally, if you can't find it, find it in home.
4.distributed Hash Tables:chord System. With a circular hash table. But the original physical location is not guaranteed.
Name resolution: Find address based on name.
Name linking:hard link or soft link.
Implementation of namespace: hierarchy

--------------------------------------------------------------------------------------------------------------- ----*/
The other 3 ways to communicate with the client server model.

1.socket. The socket appears in pairs. A socket is a combination of IP address + port number. The server always listens on each port number, and when the customer makes the request, he communicates with the port number that the server listens to. But the socket is only allowed to exchange the unstructured byte stream. RMI can be serialized by implementing
--------------------------------------------------------------------------------------------------------------- -----------

Java provides the socket class

The socket class realizes the Tcpsocket;datagramsocket class realization Udpsocket;
The socket can also be advertised more.

Import java.net.*;
Import java.io.*;

public class DataServer
{
public static void Main (String[]args)
{
try{
ServerSocket sock=new ServerSocket (6013);
while (true)
{
Socket client=sock.accept ();
PrintWriter pout=new PrintWriter (Client.getoutputstream (), true);
Pout.println (New java.util.Data.toString ());
Client.close ();
}
}
catch (Exception e)
{
System.err.println (e);
}
}
}

PrintWriter enables the server to directly use println to send to customers.

Import java.net.*;
Import java.io.*;
public class Dataclient
{
 public static void Main (String[]args)
 {
  try
  {
   sock=new Socket ("127.0.0.1", 6013);
   inputstream In=sock.getinputstream ();
   bufferreader bin=new Bufferreader (New InputStreamReader (in));
   string Line;
   while ((Line=bin.readline ())!=null)
   {
     System.out.println (line);
   }
   sock.close ();
  }
  catch (Exception e)
  {
   system.err.println (e);
 &NBSP}
 }

--------------------------------------------------------------------------------------------------------------- -----------
2.RPC
The data has a good structure. The customer issues the function to execute, and returns the result to the customer after the server side executes.
The purpose of RPC is to have the client call the server as if it were local.
The stub is just an interface.
XDR (external Data representation): Used to unify the data representations of clients and servers.
You must ensure the uniqueness of RPC data transfer. That can only pass once (Ack solve)
There are two ways to bind a service to a customer: the first is a port fix. The second is to bind through the collection point (first access to the collection point request port number, and then wait for the return port number).
RPC in 3.RMI Java
If the object is in a different JVM, it is called remote. So you can run multiple JVMs on a single machine to simulate traffic, and opening a command line means opening a JVM.

The client retains the stub (the interface of the remote method), and the local parameter can be any interface class that inherits the Java.io.serializable. Note that remote objects inherit from the Sqlremote class, and each remote method is throws remoteexception. Only remote methods can be referenced.
RMI VS RPC
The 1.RMI data structure is the object that invokes the remote object method. RPC supports subroutine programming.
The 2.RMI parameter is an object, and RPC is the normal data structure.

RMI employs stubs (in client) and backbone (server). In fact, the backbone is a stub.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.