CN114996030A - Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL - Google Patents

Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL Download PDF

Info

Publication number
CN114996030A
CN114996030A CN202210631609.3A CN202210631609A CN114996030A CN 114996030 A CN114996030 A CN 114996030A CN 202210631609 A CN202210631609 A CN 202210631609A CN 114996030 A CN114996030 A CN 114996030A
Authority
CN
China
Prior art keywords
input
server
client
output
pseudo terminal
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210631609.3A
Other languages
Chinese (zh)
Inventor
姚钰宸
李嘉铭
韩笑
孙晨菲
汲美辰
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bank of China Ltd
Original Assignee
Bank of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN202210631609.3A priority Critical patent/CN114996030A/en
Publication of CN114996030A publication Critical patent/CN114996030A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/526Mutual exclusion algorithms
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3017Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system is implementing multitasking
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3041Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is an input/output interface
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3065Monitoring arrangements determined by the means or processing involved in reporting the monitored data
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/54Interprogram communication
    • G06F9/542Event management; Broadcasting; Multicasting; Notifications

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • Quality & Reliability (AREA)
  • Mathematical Physics (AREA)
  • Multimedia (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The application discloses a method, a device and equipment for realizing an IO multiplexing pseudo terminal based on EPOLL, which can be applied to the field of big data and the field of finance, can ensure the accuracy of concurrent reading and writing of a client by using the pseudo terminal, and improve the utilization rate of system resources. The method comprises the following steps: the method comprises the steps of firstly obtaining a file lock when a client input and a server output are carried out, then mapping the input of a target pseudo terminal to the output of the server and mapping the output of the target pseudo terminal to the input of the server by using a pipeline mechanism of a Linux file, then registering a callback function which is responsible for monitoring the input of the target pseudo terminal to the server by using a Hook mechanism of a Linux kernel, analyzing the obtained input as a command line after intercepting the input of the client, transmitting the obtained input to a Shell application program to execute corresponding operation, further monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by an application program execution instruction and the output of the server to the corresponding client for playback.

Description

Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL
Technical Field
The application relates to the technical field of big data, in particular to an implementation method, device and equipment of an IO multiplexing pseudo terminal based on EPOLL.
Background
At present, a common pseudo terminal usually binds a standard input/output file descriptor of a server where an application program is located and a file descriptor of an input/output of the pseudo terminal directly, so that an input of a client is directly transmitted to the server by the pseudo terminal as an input, as shown in fig. 1, and the implementation is relatively simple and efficient. For a pseudo terminal, a server (master) and a client (slave) are in one-to-one correspondence.
However, for the existing pseudo terminal, if there are multiple clients performing read-write operations on the server at the same time, unless the server starts a pseudo terminal process for each client, the pseudo terminal cannot ensure the correctness of concurrent read-write of the client, but in this way, when the amount of concurrent read-write of the client is large, considerable system resources are occupied, resulting in low efficiency. Therefore, how to ensure the correctness of concurrent reading and writing of the client by using the pseudo terminal when a plurality of clients perform reading and writing operations on the server at the same time and improve the utilization rate of system resources is a problem to be solved urgently at present.
Disclosure of Invention
The embodiment of the application mainly aims to provide a method, a device and equipment for realizing an IO multiplexing pseudo terminal based on EPOLL, which can ensure the accuracy of concurrent reading and writing of clients by using the pseudo terminal and improve the utilization rate of system resources when a plurality of clients simultaneously perform reading and writing operations on a server.
In a first aspect, an embodiment of the present application provides a method for implementing an IO multiplexing pseudo terminal based on an EPOLL, where the method includes:
acquiring a file lock when a client inputs and a server outputs to ensure the input and output sequence during concurrent reading and writing;
mapping the input of a target pseudo terminal to the output of a server by using a pipeline mechanism of a Linux file, and mapping the output of the target pseudo terminal to the input of the server to realize the relay processing of input and output between a server and a client;
registering a callback function of the target pseudo terminal, which is responsible for monitoring input, to a server by using a Hook mechanism of a Linux kernel so as to intercept the input of the client, and analyzing the acquired input as a command line after interception so as to transmit the command line to a Shell application program to execute corresponding operation;
and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for displaying back by a preset transmission mode so as to realize IO multiplexing.
Optionally, after the file lock is acquired when the client inputs and the server outputs, the method further includes:
if the lock is successfully acquired, writing the PID of the process into the lock file and then adding a mutual exclusion lock to the file; or, if the lock acquisition fails, the target pseudo terminal sets the input process of the client to enter a blocking state, waits for the release of the lock, and does not release the file lock until the instruction is captured and analyzed, so as to ensure that only one instruction of the client is executed at the same time.
Optionally, after the intercepting and analyzing the acquired input as a command line, the method further includes:
if the analysis fails, continuing to analyze through the Linux terminal; or if the analysis is successful, calling a callback function corresponding to the instruction, transmitting the instruction to the Shell application program to execute corresponding operation, capturing the result of the operation execution again, and outputting the result to the output file area of the target pseudo terminal.
Optionally, the monitoring is performed on the input of the client and the output of the server by using the EPOLL mechanism, and the result returned by the application program execution instruction and the output of the server are transmitted to the corresponding client for playback in a preset transmission mode, so as to implement IO multiplexing, including:
and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for redisplaying in a horizontal triggering mode so as to realize IO multiplexing.
In a second aspect, an embodiment of the present application further provides an apparatus for implementing an IO multiplexing pseudo terminal based on an EPOLL, where the apparatus includes:
the acquisition unit is used for acquiring a file lock when the client inputs and the server outputs so as to ensure the input and output sequence when concurrent reading and writing are carried out;
the mapping unit is used for mapping the input of a target pseudo terminal to the output of a server side and mapping the output of the target pseudo terminal to the input of the server side by utilizing a pipeline mechanism of a Linux file, so that the relay processing of the input and the output between a server and a client side is realized;
the analysis unit is used for registering a callback function which is in charge of monitoring input of the target pseudo terminal to the server by utilizing a Hook mechanism of a Linux kernel so as to intercept the input of the client, and analyzing the acquired input as a command line after interception so as to transmit the command line to the Shell application program to execute corresponding operation;
and the echo unit is used for monitoring the input of the client and the output of the server by utilizing an EPOLL mechanism, and transmitting the result returned by the application program execution instruction and the output of the server to the corresponding client for echo by a preset transmission mode so as to realize IO multiplexing.
Optionally, the apparatus further comprises:
the first processing unit is used for writing the PID of the self process into a lock file and adding a mutual exclusion lock to the file if the lock is successfully acquired after the file lock is acquired when the client side inputs and the server side outputs; or, if the lock acquisition fails, the target pseudo terminal enters a blocking state for an input process of the client, waits for the release of the lock, and does not release the file lock until the instruction is captured and analyzed, so as to ensure that only the instruction of one client is executed at the same time.
Optionally, the apparatus further comprises:
the second processing unit is used for analyzing the acquired input as a command line after interception, and if the analysis fails, continuing to analyze the input through the Linux terminal; or if the analysis is successful, calling a callback function corresponding to the instruction, transmitting the instruction to the Shell application program to execute corresponding operation, capturing the result of the operation execution again, and outputting the result to the output file area of the target pseudo terminal.
Optionally, the playback unit is specifically configured to:
and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for redisplaying in a horizontal triggering mode so as to realize IO multiplexing.
The embodiment of the present application further provides an implementation device of an IO multiplexing pseudo terminal based on EPOLL, including: a processor, a memory, a system bus;
the processor and the memory are connected through the system bus;
the memory is configured to store one or more programs, the one or more programs including instructions, which when executed by the processor, cause the processor to perform any one of the above described methods of implementing an EPOLL-based IO multiplexing pseudo terminal.
An embodiment of the present application further provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are executed on a terminal device, the terminal device is enabled to execute any one implementation manner of the method for implementing the IO multiplexing pseudo terminal based on the EPOLL.
The embodiment of the application provides a method, a device and equipment for realizing an IO multiplexing pseudo terminal based on EPOLL, which comprises the steps of firstly obtaining a file lock when a client input and a server output are carried out to ensure the input and output sequence when concurrent reading and writing are carried out, then mapping the input of a target pseudo terminal to the output of the server by utilizing a pipeline mechanism of a Linux file, mapping the output of the target pseudo terminal to the input of the server, realizing the relay processing of the input and the output between a server and the client, then registering a callback function which is responsible for monitoring the input of the target pseudo terminal to the server by utilizing a Hook mechanism of a Linux kernel to realize the interception of the input of the client, analyzing the obtained input as a command line after the interception, transmitting the command line to a Shell application program to execute corresponding operation, and further monitoring the input of the client and the output of the server by utilizing the EPOLL mechanism, and transmitting the result returned by the application program execution instruction and the output of the server side to the corresponding client side for displaying back by a preset transmission mode so as to realize IO multiplexing. Therefore, when a plurality of clients simultaneously perform read-write operation on the server, the accuracy of concurrent read-write of the clients is ensured by using the pseudo terminal, and the utilization rate of system resources is improved.
Drawings
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings needed to be used in the description of the embodiments or the prior art will be briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic diagram illustrating an implementation of a conventional pseudo terminal according to an embodiment of the present application;
fig. 2 is a schematic flowchart of a method for implementing an IO multiplexing pseudo terminal based on an EPOLL according to an embodiment of the present application;
fig. 3 is a schematic flowchart of a process of acquiring a file lock and performing corresponding processing when a client inputs and a server outputs according to the embodiment of the present application;
fig. 4 is a schematic flow chart illustrating a process of registering a callback function of a target pseudo terminal, which is responsible for monitoring an input, in a server by using a Hook mechanism of a Linux kernel to intercept an input of a client and analyzing the intercepted input as a command line;
fig. 5 is a schematic flowchart of a process of transmitting a result returned by an application program execution instruction and an output of a server to a corresponding client for playback provided in the embodiment of the present application;
fig. 6 is a schematic composition diagram of an apparatus for implementing an IO multiplexing pseudo terminal based on an EPOLL according to an embodiment of the present disclosure.
Detailed Description
Currently, in an actual IT production environment, many shell applications are deployed on a remote Linux server. In some scenarios, when an operation and maintenance person desires to simultaneously operate multiple terminals and remotely log in a server to perform some operation and maintenance operations, the server needs to allocate multiple virtual terminals to the operation and maintenance person, and in order to ensure that input and output of multiple concurrent virtual terminals do not conflict, a pseudo terminal is required to relay input and output between a user and the server. In addition, in order to facilitate monitoring and management of the application program by operation and maintenance personnel, the application program is expected to support some self-defined CLI commands in some scenes, and at the moment, the pseudo terminal can monitor instructions input by a keyboard, send the instructions into the application program to realize corresponding operations, and print and output results of the operation execution in a visual form.
However, the current pseudo terminal usually directly binds the file descriptors of the standard input and output of the service end where the application program is located and the file descriptors of the input and output of the pseudo terminal, so that the input of the client end is directly transmitted to the service end by the pseudo terminal as an input, as shown in fig. 1, although the implementation is relatively simple and efficient. However, for a pseudo terminal, the server (master) and the client (slave) are in one-to-one correspondence. If a plurality of clients simultaneously perform read-write operation on the server, the pseudo terminal cannot ensure the accuracy of concurrent read-write of the clients unless the server starts a pseudo terminal process for each client, but in this way, when the concurrent amount of read-write of the clients is large, considerable system resources are occupied, and the efficiency is low. Therefore, how to ensure the correctness of concurrent reading and writing of the client by using the pseudo terminal when a plurality of clients perform reading and writing operations on the server at the same time and improve the utilization rate of system resources is a problem to be solved urgently at present.
In order to solve the above-mentioned drawbacks, an embodiment of the present application provides a method for implementing an EPOLL-based IO multiplexing pseudo terminal, which includes obtaining a file lock at the time of client input and server output to ensure the order of input and output at the time of concurrent read and write, mapping the input of a target pseudo terminal to the output of a server by using a pipeline mechanism of a Linux file, mapping the output of the target pseudo terminal to the input of the server, and implementing relay processing of input and output between a server and a client, registering a callback function of the target pseudo terminal, which is responsible for monitoring input, to the server by using a Hook mechanism of a Linux kernel to intercept the input of the client, parsing the obtained input after interception as a command line to transmit to a Shell application program to perform corresponding operations, and further monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting the result returned by the application program execution instruction and the output of the server side to the corresponding client side for displaying back by a preset transmission mode so as to realize IO multiplexing. Therefore, when a plurality of clients simultaneously perform read-write operation on the server, the accuracy of concurrent read-write of the clients is ensured by using the pseudo terminal, and the utilization rate of system resources is improved.
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
First embodiment
Referring to fig. 2, a schematic flow chart of a method for implementing an IO multiplexing pseudo terminal based on an EPOLL according to this embodiment is provided, where the method includes the following steps:
s201: and acquiring a file lock when the client inputs and the server outputs so as to ensure the input and output sequence during concurrent reading and writing.
In this embodiment, in order to ensure the correctness of concurrent reading and writing of a client by using a pseudo terminal and improve the utilization rate of system resources when a plurality of clients perform reading and writing operations on a server at the same time, the present application first obtains a file lock when the client inputs and the server outputs, so as to ensure the input and output sequence during concurrent reading and writing. That is, at the server, the file lock is used to ensure that only one client can write the input file of the pseudo terminal at the same time when concurrent writing is performed on the input file, and only after the current client completes writing and releases the file lock, the writing operations of other clients are written in sequence.
Specifically, as shown in fig. 3, an optional implementation manner is that, before accepting input from a client, a target pseudo terminal process tries to acquire a process file lock in a specified directory, and if the acquisition of the lock is successful, a PID of its own process is written into the lock file, and then a mutual exclusion lock is added to the file, so as to prevent other clients from inputting an interrupt instruction to the parsing process; or, if the lock acquisition fails, the target pseudo terminal sets the input process of the client to enter a blocking state, waits for the release of the lock, and does not release the file lock until the instruction is captured and analyzed, so as to ensure that only one instruction of the client is executed at the same time.
It should be noted that starvation may cause deadlock if the client input process is in a blocked state from a long time. Therefore, it is also necessary for the target pseudo terminal to return a failure result when the number of times of failure of acquiring the lock by the client is too large, so that the target pseudo terminal abandons the lock acquisition. The standard output of the server is set to be buffer-free IO so that the output result of each instruction execution can be captured by the input of the target pseudo terminal in time, and is not retained in the buffer area. Similarly, the input of the target pseudo terminal is set to be buffer-free IO, so that the buffer area can be forcibly refreshed during writing the instruction every time, and the instruction analysis error caused by the input residue of the previously pressed instruction is avoided.
S202: and mapping the input of the target pseudo terminal to the output of the server by using a pipeline mechanism of a Linux file, and mapping the output of the target pseudo terminal to the input of the server to realize the relay processing of the input and the output between the server and the client.
S203: and registering a callback function of the target pseudo terminal, which is responsible for monitoring input, to the server by using a Hook mechanism of a Linux kernel so as to intercept the input of the client, and analyzing the acquired input as a command line after interception so as to transmit the command line to the Shell application program to execute corresponding operation.
In this embodiment, after the relay processing of the input and output between the server and the client is implemented through step S202, a Hook mechanism of the Linux kernel may be further utilized to register a callback function of the target pseudo terminal, which is responsible for monitoring the input, to the server, so as to implement interception of the input of the client, and after the interception, the obtained input is analyzed as a command line, so as to be transmitted to the Shell application program to execute a corresponding operation, so as to execute the subsequent step S204.
Specifically, as shown in fig. 4, an optional implementation manner is that after capturing an input instruction input to the client, the target pseudo terminal performs syntax analysis and command matching according to a callback function registered in the Linux kernel module, the realization of the callback function can be customized according to the difference of application programs and the service requirements of users, and if the instruction analysis fails, the instruction is thrown out and continues to be analyzed by the Linux terminal; or if the analysis is successful, calling a callback function corresponding to the instruction, transmitting the callback function to the shell application program to execute corresponding operation, capturing the result of the operation execution again, and outputting the result to the output file area of the target pseudo terminal.
S204: and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for displaying back by a preset transmission mode so as to realize IO multiplexing.
In this embodiment, the obtained input is analyzed as a command line in step S203, and is transmitted to the Shell application program to perform a corresponding operation, and then the input of the client and the output of the server may be further monitored by using an EPOLL mechanism, and the result returned by the application program execution instruction and the output of the server are transmitted to the corresponding client for playback in a preset transmission manner (which may be set according to actual conditions, and is not limited in this application), so as to implement IO multiplexing and ensure the performance of the target pseudo terminal during multiple concurrent reading and writing.
An optional implementation manner is that an EPOLL mechanism may be used to monitor the input of the client and the output of the server, and a result returned by the application program execution instruction and the output of the server are transmitted to the corresponding client for playback in a horizontal triggering manner, so as to implement IO multiplexing.
Specifically, in the present implementation, as shown in fig. 5, a handle and an event may be created after the pseudo terminal is started using an EPOLL mechanism, and registered in a listening list of the Linux kernel, and then continuously listening whether the EPOLL event is triggered. Here, a horizontal triggering mode may be used, once an IO event occurs in a file descriptor monitored by the EPOLL, the EPOLL reads the event, maps input and output contents in the file to an input and output area of the pseudo terminal, completes monitoring of instruction input and capturing of an instruction result, and after a result of executing the instruction is returned to a server output area, the pseudo terminal triggers the EPOLL event to send the returned result to a socket of the client, and then completes playback of the execution result on a terminal interface of the client.
In this way, by executing the steps S201 to S204, the operation and maintenance management is performed on the service end where the application program is located in a pseudo terminal manner, and the EPOLL mechanism supports a plurality of pseudo terminals to operate online at the same time. Therefore, operation and maintenance developers can operate and manage the application programs deployed on the remote server conveniently, a plurality of users can log in the terminal to operate simultaneously, the working efficiency of the operation and maintenance developers can be improved, the pseudo terminal is adopted as an input and output relay, some non-regular operations can be filtered as a safety guarantee, and the safety of the running environment of the application programs of the server is enhanced.
To sum up, the method for implementing an IO multiplexing pseudo terminal based on EPOLL according to this embodiment first obtains a file lock when the client inputs and the server outputs to ensure the order of input and output when reading and writing are performed concurrently, then maps the input of the target pseudo terminal to the output of the server by using the pipeline mechanism of the Linux file, maps the output of the target pseudo terminal to the input of the server, and implements relay processing of input and output between the server and the client, and then registers the callback function of the target pseudo terminal, which is responsible for monitoring the input, to the server by using the Hook mechanism of the Linux kernel to intercept the input of the client, and after the interception, takes the obtained input as a command line to analyze the command line to be transmitted to the Shell application program to perform corresponding operations, so as to monitor the input of the client and the output of the server by using the EPOLL mechanism, and transmitting the result returned by the application program execution instruction and the output of the server side to the corresponding client side for displaying back by a preset transmission mode so as to realize IO multiplexing. Therefore, when a plurality of clients simultaneously perform read-write operation on the server, the accuracy of concurrent read-write of the clients is ensured by using the pseudo terminal, and the utilization rate of system resources is improved.
Second embodiment
In this embodiment, a device for implementing an IO multiplexing pseudo terminal based on EPOLL will be described, and for related contents, please refer to the above method embodiments.
Referring to fig. 6, a schematic composition diagram of an apparatus for implementing an IO multiplexing pseudo terminal based on an EPOLL provided in this embodiment specifically includes:
an obtaining unit 601, configured to obtain a file lock when the client inputs and the server outputs, so as to ensure an input and output sequence when reading and writing are performed concurrently;
a mapping unit 602, configured to map an input of a target pseudo terminal to an output of a server and map an output of the target pseudo terminal to an input of the server by using a pipeline mechanism of a Linux file, so as to implement relay processing of input and output between a server and a client;
the analysis unit 603 is configured to register, by using a Hook mechanism of a Linux kernel, a callback function of the target pseudo terminal, which is responsible for monitoring input, to the server, so as to intercept the input of the client, and analyze, after the interception, the acquired input as a command line, so as to transmit the command line to the Shell application program to perform corresponding operation;
and the playback unit 604 is configured to monitor the input of the client and the output of the server by using an EPOLL mechanism, and transmit a result returned by the application program execution instruction and the output of the server to the corresponding client for playback in a preset transmission manner, so as to implement IO multiplexing.
In an implementation manner of this embodiment, the apparatus further includes:
the first processing unit is used for writing the PID of the self process into a lock file and adding a mutual exclusion lock to the file if the lock is successfully acquired after the file lock is acquired when the client side inputs and the server side outputs; or, if the lock acquisition fails, the target pseudo terminal sets the input process of the client to enter a blocking state, waits for the release of the lock, and does not release the file lock until the instruction is captured and analyzed, so as to ensure that only one instruction of the client is executed at the same time.
In an implementation manner of this embodiment, the apparatus further includes:
the second processing unit is used for analyzing the acquired input as a command line after interception, and if the analysis fails, the analysis is continued through a Linux terminal; or if the analysis is successful, calling a callback function corresponding to the instruction, transmitting the instruction to the Shell application program to execute corresponding operation, capturing the result of the operation execution again, and outputting the result to the output file area of the target pseudo terminal.
In an implementation manner of this embodiment, the echo unit 604 is specifically configured to:
and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for redisplaying in a horizontal triggering mode so as to realize IO multiplexing.
To sum up, the apparatus for implementing an IO multiplexing pseudo terminal based on EPOLL according to this embodiment first obtains a file lock when the client inputs and the server outputs to ensure the order of input and output when reading and writing are performed concurrently, then maps the input of the target pseudo terminal to the output of the server by using the pipeline mechanism of the Linux file, maps the output of the target pseudo terminal to the input of the server, and implements relay processing of input and output between the server and the client, and then registers the callback function of the target pseudo terminal, which is responsible for monitoring the input, to the server by using the Hook mechanism of the Linux kernel to intercept the input of the client, and after the interception, parses the obtained input as a command line to be transmitted to the Shell application program to perform corresponding operations, and further can monitor the input of the client and the output of the server by using the EPOLL mechanism, and transmitting the result returned by the application program execution instruction and the output of the server side to the corresponding client side for displaying back by a preset transmission mode so as to realize IO multiplexing. Therefore, when a plurality of clients simultaneously perform read-write operation on the server, the accuracy of concurrent read-write of the clients is ensured by using the pseudo terminal, and the utilization rate of system resources is improved.
Further, an embodiment of the present application further provides a device for implementing an IO multiplexing pseudo terminal based on an EPOLL, including: a processor, a memory, a system bus;
the processor and the memory are connected through the system bus;
the memory is configured to store one or more programs, the one or more programs including instructions, which when executed by the processor, cause the processor to perform any of the methods of implementing an EPOLL-based IO multiplexing pseudo terminal described above.
Further, an embodiment of the present application further provides a computer-readable storage medium, where instructions are stored in the computer-readable storage medium, and when the instructions are executed on a terminal device, the terminal device is caused to execute any one of the above methods for implementing an EPOLL-based IO multiplexing pseudo terminal.
As can be seen from the above description of the embodiments, those skilled in the art can clearly understand that all or part of the steps in the above embodiment methods can be implemented by software plus a necessary general hardware platform. Based on such understanding, the technical solution of the present application may be essentially or partially implemented in the form of a software product, which may be stored in a storage medium, such as a ROM/RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network communication device such as a media gateway, etc.) to execute the method according to the embodiments or some parts of the embodiments of the present application.
It should be noted that, in the present specification, the embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
In addition, the method, the device and the equipment for realizing the IO multiplexing pseudo terminal based on the EPOLL can be used in the field of big data and the field of finance. The foregoing is merely an example, and does not limit the application fields of the method, apparatus, and device for implementing the IO multiplexing pseudo terminal based on EPOLL provided by the present invention.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (10)

1. An implementation method of an IO multiplexing pseudo terminal based on EPOLL is characterized by comprising the following steps:
acquiring a file lock when a client inputs and a server outputs to ensure the input and output sequence when concurrent reading and writing;
mapping the input of a target pseudo terminal to the output of a server by using a pipeline mechanism of a Linux file, and mapping the output of the target pseudo terminal to the input of the server to realize the relay processing of input and output between a server and a client;
registering a callback function of the target pseudo terminal, which is responsible for monitoring input, to a server by utilizing a Hook mechanism of a Linux kernel so as to intercept the input of a client, and analyzing the acquired input as a command line after interception so as to transmit the command line to a Shell application program to execute corresponding operation;
and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for displaying back by a preset transmission mode so as to realize IO multiplexing.
2. The method of claim 1, wherein after acquiring the file lock at the client input and the server output, the method further comprises:
if the lock is successfully acquired, writing the PID of the process into the lock file and then adding a mutual exclusion lock to the file; or, if the lock acquisition fails, the target pseudo terminal sets the input process of the client to enter a blocking state, waits for the release of the lock, and does not release the file lock until the instruction is captured and analyzed, so as to ensure that only one instruction of the client is executed at the same time.
3. The method of claim 1, wherein after parsing the captured input as a command line after intercepting, the method further comprises:
if the analysis fails, continuing to analyze through a Linux terminal; or if the analysis is successful, calling a callback function corresponding to the instruction, transmitting the instruction to the Shell application program to execute corresponding operation, capturing the result of the operation execution again, and outputting the result to the output file area of the target pseudo terminal.
4. The method according to any one of claims 1 to 3, wherein the monitoring of the input of the client and the output of the server by using the EPOLL mechanism and the transmission of the result returned by the application program execution instruction and the output of the server to the corresponding client for displaying back by a preset transmission mode to realize IO multiplexing comprises:
and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for redisplaying in a horizontal triggering mode so as to realize IO multiplexing.
5. An apparatus for implementing an EPOLL-based IO multiplexing dummy terminal, the apparatus comprising:
the acquisition unit is used for acquiring a file lock when the client inputs and the server outputs so as to ensure the input and output sequence when concurrent reading and writing are carried out;
the mapping unit is used for mapping the input of a target pseudo terminal to the output of a server side and mapping the output of the target pseudo terminal to the input of the server side by utilizing a pipeline mechanism of a Linux file, so that the relay processing of the input and the output between a server and a client side is realized;
the analysis unit is used for registering a callback function of the target pseudo terminal, which is responsible for monitoring input, to a server by utilizing a Hook mechanism of a Linux kernel so as to intercept the input of a client, and analyzing the acquired input serving as a command line after interception so as to transmit the command line to a Shell application program to execute corresponding operation;
and the playback unit is used for monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting the result returned by the application program execution instruction and the output of the server to the corresponding client for playback in a preset transmission mode so as to realize IO multiplexing.
6. The apparatus of claim 5, further comprising:
the first processing unit is used for writing the PID of the self process into a lock file and adding a mutual exclusion lock to the file if the lock is successfully acquired after the file lock is acquired when the client side inputs and the server side outputs; or, if the lock acquisition fails, the target pseudo terminal sets the input process of the client to enter a blocking state, waits for the release of the lock, and does not release the file lock until the instruction is captured and analyzed, so as to ensure that only one instruction of the client is executed at the same time.
7. The apparatus of claim 6, further comprising:
the second processing unit is used for analyzing the acquired input as a command line after interception, and if the analysis fails, continuing to analyze the input through the Linux terminal; or if the analysis is successful, calling a callback function corresponding to the instruction, transmitting the instruction to the Shell application program to execute corresponding operation, capturing the result of the operation execution again, and outputting the result to the output file area of the target pseudo terminal.
8. The device according to any one of claims 5 to 7, wherein the rendering unit is specifically configured to:
and monitoring the input of the client and the output of the server by using an EPOLL mechanism, and transmitting a result returned by the application program execution instruction and the output of the server to the corresponding client for displaying back in a horizontal triggering mode so as to realize IO multiplexing.
9. An apparatus for implementing an IO multiplexing pseudo terminal based on an EPOLL, comprising: a processor, a memory, a system bus;
the processor and the memory are connected through the system bus;
the memory is to store one or more programs, the one or more programs comprising instructions, which when executed by the processor, cause the processor to perform the method of any of claims 1-4.
10. A computer-readable storage medium having stored therein instructions that, when executed on a terminal device, cause the terminal device to perform the method of any one of claims 1-4.
CN202210631609.3A 2022-06-06 2022-06-06 Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL Pending CN114996030A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210631609.3A CN114996030A (en) 2022-06-06 2022-06-06 Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210631609.3A CN114996030A (en) 2022-06-06 2022-06-06 Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL

Publications (1)

Publication Number Publication Date
CN114996030A true CN114996030A (en) 2022-09-02

Family

ID=83032321

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210631609.3A Pending CN114996030A (en) 2022-06-06 2022-06-06 Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL

Country Status (1)

Country Link
CN (1) CN114996030A (en)

Similar Documents

Publication Publication Date Title
CN107436844B (en) Method and device for generating interface use case aggregate
CN112380093A (en) Operation and maintenance processing method and device and computer equipment
CN110955409B (en) Method and device for creating resources on cloud platform
CN109783345B (en) Method and system for testing small program performance
CN113407383B (en) Main and standby system switching method and device, server and main and standby system
CN111641676B (en) Method and device for constructing third-party cloud monitoring service
CN110598135A (en) Network request processing method and device, computer readable medium and electronic equipment
CN114780569A (en) Input and output proxy method and device of mimicry redis database
WO2020177519A1 (en) Debugging method executed on smart terminal and software debugging device
CN113296981A (en) Data processing method and device, electronic equipment and storage medium
CN111200651A (en) Method, system, device and medium for timed calling of microservice
CN109375874B (en) Method, device and equipment for calling distributed storage
CN109032911B (en) Frame rate detection method and device for mobile device and electronic device
CN114996030A (en) Method, device and equipment for realizing IO multiplexing pseudo terminal based on EPOLL
CN115237481A (en) Method, device and equipment for driving external equipment and storage medium
CN112379952B (en) Method for implementing cross-process callback
CN112416698B (en) Expansion method and device of monitoring system, storage medium and electronic equipment
CN110347597B (en) Interface testing method and device of picture server, storage medium and mobile terminal
CN113127369A (en) Processing method and device for execution script
CN112818336A (en) Data access method, data access device and computer readable storage medium
CN111124907A (en) Mobile phone game testing method and device and server
CN112231290A (en) Method, device and equipment for processing local log and storage medium
CN113391931A (en) Remote control method and device based on Bluetooth, computer equipment and storage medium
CN110716841A (en) Monitoring data collection method, device and equipment
CN113760631A (en) Page loading duration determination method, device, equipment and storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination