Method for enhancing reliability of program of multi-replica contrast mechanism based on code segment

The invention discloses a method for enhancing the reliability of a program of a multi-replica contrast mechanism based on a code segment. In the method, an kernel thread is started as an initialization thread, the initialization thread obtains a process memory information, two replicas of a process code segment are stored in a physical memory, the process code segment is also divided into memory domains with the fixed size, the kernel threads with a corresponding amount are started as a consistency maintenance thread to maintain the consistency of a process code domain and a replica thereof in real time according to a division result, and program code segment errors caused by various software and hardware faults are discovered and recovered in time. The invention is simple to realize, is transparent to a protected process and can efficiently detect the program code segment errors, thereby preventing program crash and even system invalidation caused by the code segment errors and improving the operation reliability of the program.