Knowledge review and process related knowledge and operations

Source: Internet
Author: User

1, the development of programming language:

Machine language: Binary

Assembly language: Instruction, command form

High-level language: Process-oriented (C) object-oriented (Python,c++,java)

2, the operating system objectives:

To make it easier for users to use the system

3, the composition of the computer:

CPU, motherboard, storage, input, output

4, parallel, concurrency

Concurrency: Refers to two or more things that execute simultaneously at the same time interval (macro is parallel, microscopic is serial)

Parallel: Refers to two or more things that execute simultaneously at the same time interval

5. The process consists of three parts:

Code snippet, data segment, PCB (Process control block)

6, the process of three basic states:

Ready state: In addition to the CPU, the process gets all the resources it needs

Execution status: The process gets all the resources it needs to be executing

Blocking status: The process has abandoned the CPU for some reason and cannot continue execution, at which time the processes are in memory waiting state

  

7. Introduction of operating system

DOS: Single-user single process

Windows: Single-user multi-process (early windows)

UNIX: Multi-user process

8, why should have an operating system?

1, encapsulating all the hardware interface, make users more convenient to use

2, for all resources within the computer, reasonable scheduling and distribution

9, Multi-process module

Multiprocessing

Process

10, process-related knowledge, operation

1) synchronous, asynchronous, blocking, non-blocking

Synchronization: Refers to sending a request, need to wait to return, and then be able to send the next request, there is a wait process;

Async: Refers to sending a request that does not need to wait for a return and can send the next request again at any time, i.e. no wait.

To do something until it is done, unless it is timed out

Non-blocking: try to do, if not done, do not do (return directly), if you can do, do it.

Xiao Li drank to drink water, then went to boil boiling water.
1, Xiao Li put the kettle on the stove, waiting for the water to boil. (Synchronous blocking)
Xiao Li felt that it was too time-consuming.
2, Xiao Li put the kettle on the stove, go to the living room to watch TV, and occasionally go to the kitchen to see if the water is open. (Synchronous non-blocking)
Xiao Li still felt so tired, so he bought the kettle that would ring the flute. When the water is open, it makes a sound.
3, Xiao Li put the kettle on the stove, waiting for the kettle to make a sound. (Asynchronous blocking)
It doesn't make much sense to think such a fool
4, Xiao Li put the kettle on the stove, go to the living room to watch TV, the kettle rang no longer to see it, rang again to get the pot. (Asynchronous non-blocking)
That's good.

2) Two ways to open a process:

A, p = Process (target=none,args= (,) Target: is the task to be performed by the child process, args: is the parameter passed by the parent process to the child process

B, custom class, inherit process parent class

3) Common methods of process

A, start () open a process the bottom call is P.run () this method

B, join () asynchronous synchronization (that is, let the parent process stay in the join this sentence, waiting for the child process to finish, the parent process continues to execute)--->>> must be behind start ()

C, is_alive () determine if the process is alive

D, terminate () kill process

4) Common properties of the process

A, p.name = name give p process a name

B, P.pid returns the PID of the P process (gets the current process's pid-->os.getpid () gets the PID of the parent process of the current process---->os.getppid ())

C, P.daemon = True to set the P process to daemon. (True for daemons, false for normal processes)---->>> must precede start ()

Two features of the daemon process:

The daemon ends with the end of the parent process

Daemons can no longer create child processes

add : 1. No memory sharing between multiple processes

2, how to change the relationship between the parent process and the child process into synchronous or asynchronous?

When the parent process executes the join, it becomes synchronous (the join must be placed behind start ()), no join is performed, and the parent and child processes are asynchronous relationships

 from Import Process def func (i):     Global N     Print # error, the Func function's memory cannot be shared with the memory under the IF condition if __name__ ' __main__ ' :     = 1     = Process (target=func,args= (,))    P.start ()

Here are some of the code for the operation:

 fromMultiprocessingImportProcess#importing multi-process modulesImport TimeImportRandomdeffunc (i): Time.sleep (1)    Print('I am%s'%i)if __name__=='__main__':#This line of code must be necessary to run the PycharmL =[] Addr= ['Taiyuan's','Changzhi's','Lvliang's','Yuncheng's']     forIinchaddr:p= Process (target=func,args= (i,))#instantiate a child process object and pass the corresponding parametersP.start ()#turn on child processesl.append (P) p.join ()#asynchronous to synchronous (must wait for the previous execution to execute next)    #[I.join () for i in L] # acts like P.join (), but it's fasterTime.sleep (2)    Print('I choose%s'% Random.choice (addr))
######################### #开启子进程的一种方式 ##################### fromMultiprocessingImportProcessImportOSImport Timedeffunc (i): Time.sleep (1)    Print('here is the child process, the PID of the child process is%s, the PID of the parent process of the child process is%s'%(Os.getpid (), Os.getppid ()))if __name__=='__main__':     forIinchRange (2): P= Process (target=func,args=(i,)) P.start ()Print('here is the parent process, the parent process's PID is%s, the parent process's parent process PID is%s'%(Os.getpid (), Os.getppid ()))################### #开启子进程的另外一种方式, ################### in an inherited wayclassmyprocess (Process):def __init__(Self,name): Super (myprocess, self).__init__() Self.name=namedefRun (self):Print('This is the child process that is opened in the way that inherits the class, which is%s'%self.name)if __name__=='__main__': P1= Myprocess ('Guo') P1.start ()#The interpreter tells the operating system to help me open a child process ready state (start automatically calls the Run method in myprocess)    #P1.run () # Tell the operating system, now help me execute this sub-process immediately
######### #杀死子进程 ############## fromMultiprocessingImportProcessImport Timedeffunc ():Print(123)if __name__=='__main__': P= Process (target=func,) P.start () Time.sleep (0.15)#0.1 not printing 123,0.2 are false, more perfect results.P.terminate ()#Kill P Process    Print('is the child process still alive? ', P.is_alive ())#is_alive () returns a bool value, which means true is alive, otherwise it means dead.Time.sleep (1)    Print('is the child process still alive? ', P.is_alive ())#Printing results:#123#is the child process still alive? True#is the child process still alive? False
################### #守护进程 #################### fromMultiprocessingImportProcessImport Timedeffunc (): forIinchRange (10): Time.sleep (1)        Print('Child process%s'% Time.strftime ('%h:%m:%s'))if __name__=='__main__': P= Process (target=func) P.daemon= True#set P process as daemon and must be set before start (will end with the end of the parent process)P.start () time.sleep (5)#results are only generated for 4 sub-processes    Print('Parent Process')

Knowledge review and process related knowledge and operations

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.