A method and device for implementing device operation
By using the unique identifier of the file sharing activation process in the embedded device, simple switching and console connection management between multiple Shell processes are realized, which solves the problems of high switching complexity and poor versatility in the existing technology, and improves the efficiency of the process. Ease of device operation and portability.
Patent Information
- Application Number
- CN201910970949.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2019-10-17
- Publication Date
- 2024-09-13
- Estimated Expiration
- 2039-10-17
AI Technical Summary
In embedded devices, switching between multiple Shell processes is highly complex, has poor versatility and portability, and it is difficult for existing solutions to implement a simple and easy switching method.
By starting a specified number of Shell processes in the embedded device, and using the unique identifier of the file sharing activation process, the inactive process can periodically read files to determine whether to switch to an active process, thereby realizing switching between processes and console connection management.
It reduces the complexity of switching between multiple Shell processes, improves the versatility and portability of the method, and simplifies device operations.
Smart Images

Figure CN112685143B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method and apparatus for implementing device operation. Background Art
[0002] In embedded devices, the Shell process is connected to the console " / dev / console" as a command parser, and provides a command line interface to managers by reading and writing the console. Usually, an embedded device has only one console, and the console can only be connected to one Shell process at a time to exchange information. When there are multiple Shell processes in the system that need to perform input and output at the same time, the limited console resources often become the bottleneck of the system. In existing solutions, if you need to switch between multiple Shell processes, you need to use complex programming to complete the preemption of the console, which has poor versatility and portability. How to use a simple and easy method to achieve switching between multiple Shell processes has become a problem that needs to be solved urgently. Summary of the invention
[0003] The present invention provides a method and device for realizing device operation, which solves the problems of high complexity, poor versatility and poor portability when an embedded device realizes switching between multiple Shell processes.
[0004] In a first aspect, the present invention provides a method for implementing device operation, which is applied to an embedded device and comprises the following steps:
[0005] Starting a specified number of Shell processes; randomly selecting one Shell process from the specified number of Shell processes as an activated Shell process, and updating a unique identifier of the activated Shell process to the first file;
[0006] Any inactivated Shell process periodically reads the unique identifier in the first file to determine whether the inactivated Shell process can be switched to an activated Shell process; if so, the inactivated Shell process is switched to an activated Shell process and establishes a connection with the console, waiting for parsing of user instructions.
[0007] The starting of a specified number of Shell processes includes:
[0008] Each time a Shell process is started, if the Shell process currently started is the first Shell process started, the first file is created, the unique identifier of the Shell process is written into the first file, the Shell process is set as an activated Shell process, and a connection is established between the Shell process and the console; otherwise, the Shell process is set as an inactivated Shell process, and a timer is started for the Shell process.
[0009] Preferably, starting a specified number of Shell processes includes:
[0010] Each time a Shell process is started, if the Shell process currently started is the first Shell process started, the index value of the Shell process currently started is set as the initial index value, a second file and the first file are created, the index value of the Shell process is written into the second file and the first file respectively, the Shell process is set as the activated Shell process, and the Shell process is connected to the console; otherwise, the index value in the second file is read, the index value is updated according to the set rule and is set as the index value of the Shell process currently started, the index value of the Shell process is updated into the second file, the Shell process is set as the inactivated Shell process, and a timer is started for the Shell process.
[0011] The step of selecting one Shell process from the specified number of Shell processes and setting it as an activated Shell process, and updating the unique identifier of the activated Shell process to the first file, comprises:
[0012] When a user instruction is input to set any one of the specified number of Shell processes as an activated Shell process, if the unique identifier of the Shell process set as the activated Shell process is not equal to the unique identifier of the Shell process currently connected to the console, the Shell process currently connected to the console updates the unique identifier of the Shell process set as the activated Shell process into the first file, and the Shell process currently connected to the console sets itself as an inactivated Shell process, disconnects from the console, and starts the timer.
[0013] Any of the inactivated Shell processes periodically reads the unique identifier in the first file to determine whether the inactivated Shell process can be switched to an activated Shell process, including:
[0014] After the timer of any inactivated Shell process expires, the Shell process reads the unique identifier in the first file to determine whether the unique identifier of the Shell process is the same as the unique identifier in the first file; if they are the same, the timer of the Shell process is closed; otherwise, the timer of the Shell process is opened again.
[0015] In a second aspect, the present invention provides a device for implementing device operation, which is applied to an embedded device and specifically includes:
[0016] The startup module is used to start a specified number of Shell processes;
[0017] A Shell process module, configured to select any one of the specified number of Shell processes as an active Shell process, and update the unique identifier of the active Shell process into a first file; and to periodically read the unique identifier in the first file for any inactive Shell process, and determine whether the inactive Shell process can be switched to an active Shell process; if so, the inactive Shell process is switched to an active Shell process and establishes a connection with a console, waiting for parsing of a user instruction;
[0018] The console module is used to forward the input user instructions to the Shell process connected to the console for parsing and processing; and to forward the results of the parsing and processing to the Shell process connected to the console for output.
[0019] The startup module is specifically used for: each time a Shell process is started, if the Shell process currently started is the first Shell process started, creating the first file, writing the unique identifier of the Shell process into the first file, setting the Shell process as an activated Shell process, and establishing a connection between the Shell process and the console; otherwise, setting the Shell process as an inactivated Shell process and starting a timer for the Shell process.
[0020] Preferably, the startup module is specifically used for: each time a Shell process is started, if the Shell process currently started is the first Shell process started, setting the index value of the Shell process currently started as the initial index value, creating a second file and the first file, writing the index value of the Shell process into the second file and the first file respectively, setting the Shell process as the activated Shell process, and establishing a connection between the Shell process and the console; otherwise, reading the index value in the second file, setting the updated value of the index value according to the set rule as the index value of the Shell process currently started, updating the index value of the Shell process into the second file, setting the Shell process as the inactivated Shell process, and starting a timer for the Shell process.
[0021] The Shell process module is specifically used for: when a user instruction is input to set any one of the specified number of Shell processes as an activated Shell process, if the unique identifier of the Shell process set as activated is not equal to the unique identifier of the Shell process currently connected to the console, the Shell process currently connected to the console updates the unique identifier of the Shell process set as activated into the first file, and the Shell process currently connected to the console sets itself as an inactivated Shell process, disconnects from the console, and starts the timer.
[0022] Furthermore, the Shell process module is specifically used for: after the timer of any inactivated Shell process expires, the Shell process reads the unique identifier in the first file to determine whether the unique identifier of the Shell process is the same as the unique identifier in the first file; if they are the same, closing the timer of the Shell process; otherwise, opening the timer of the Shell process again.
[0023] In summary, the present invention shares the unique identifier of the activated Shell process in a file manner, so that each inactivated Shell process can determine whether it can be switched to an activated Shell process by regularly reading the file. The method of the present invention reduces the complexity of switching between multiple Shell processes and has good versatility and portability. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0025] Figure 1 A flow chart of a method for implementing device operation provided by an embodiment of the present invention is shown.
[0026] Figure 2 A schematic diagram of an implementation device for device operation provided by an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0027] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments. The following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without making creative work are within the scope of protection of the present invention.
[0028] The following describes the embodiments in detail.
[0029] Embodiment 1
[0030] The embodiment of the present invention provides a method for implementing device operation, which is applied to embedded devices. The processing flow chart is as follows: Figure 1 As shown, the following steps are included:
[0031] Step S101, start a specified number of Shell processes.
[0032] In this step, when the embedded device is initialized in the system, a specified number of Shell processes can be started by using scripts or the like, and the number of Shell processes can be specified according to actual needs. Each time a Shell process is started, if the currently started Shell process is the first Shell process started, the first file is created, the unique identifier of the Shell process is written into the first file, the Shell process is set as an activated Shell process, and the Shell process is connected to the console; otherwise, the Shell process is set as an inactivated Shell process, and a timer is opened for the Shell process. Among them, the time intervals of the timers of all inactivated Shell processes can be equal. It should be noted that the unique identifier of the Shell process can be the process identifier (Process Identifier, referred to as PID) of the Shell process.
[0033] Step S102: randomly select one Shell process from the specified number of Shell processes and set it as an activated Shell process, and update the unique identifier of the activated Shell process into the first file.
[0034] In this step, when a user instruction is input to set any one of the specified number of Shell processes as an activated Shell process, if the unique identifier of the Shell process set as the activated Shell process is not equal to the unique identifier of the Shell process currently connected to the console, the Shell process currently connected to the console updates the unique identifier of the Shell process set as the activated Shell process into the first file, and the Shell process currently connected to the console sets itself as an inactivated Shell process, disconnects from the console, and starts the timer.
[0035] Preferably, before any one of the specified number of Shell processes is set as the active Shell process, a user instruction can be input to view the unique identifiers of all the specified number of Shell processes, and the unique identifier of the Shell to be set as the active Shell is obtained as a parameter of the Shell switching instruction.
[0036] Step S103, any inactivated Shell process periodically reads the unique identifier in the first file to determine whether the inactivated Shell process can be switched to an activated Shell process; if so, the inactivated Shell process is switched to an activated Shell process and establishes a connection with the console, waiting for parsing of user instructions.
[0037] Among them, any inactivated Shell process periodically reads the unique identifier in the first file to determine whether the inactivated Shell process can be switched to the activated Shell process, including: after the timer of any inactivated Shell process expires, the Shell process reads the unique identifier in the first file to determine whether the unique identifier of the Shell process is the same as the unique identifier in the first file; if they are the same, closing the timer of the Shell process; otherwise, opening the timer of the Shell process again.
[0038] For example, suppose three Shell processes are started: Shell1 process, Shell2 process, and Shell3 process, among which Shell1 process is the currently activated Shell process, and establishes a connection with the console " / dev / console" to wait for user input from the console " / dev / console". If the user inputs an instruction to set Shell3 process as the activated Shell process, after the Shell1 process parses the instruction, it first reads the unique identifier in the first file, and compares whether the unique identifier in the first file is the same as the unique identifier of the Shell1 process. If they are the same, the Shell1 process will no longer process the instruction and continue to wait for user input from the console " / dev / console"; otherwise, the Shell1 process will update the unique identifier of the Shell3 process to the first file, and then the Shell1 process will set itself as an inactivated Shell process, disconnect the connection with the console " / dev / console", and start the timer of the Shell1 process. It should be noted that at this time, the Shell3 process is still an inactivated Shell process. When the timer of the Shell2 process expires, the Shell2 process reads the unique identifier in the first file, and finds that its unique identifier is different from the unique identifier in the first file, then turns on the timer of the Shell2 process again and continues to wait. When the timer of the Shell3 process expires, the Shell3 process reads the unique identifier in the first file, and finds that its unique identifier is the same as the unique identifier in the first file, then the Shell3 process turns off its own timer, switches to the activated Shell process, and establishes a connection with the console " / dev / console", waiting for the user's instructions to be parsed and processed.
[0039] This embodiment shares the unique identifier of the activated Shell process in a file mode, so that each inactivated Shell process can determine whether it can be switched to an activated Shell process by regularly reading the file. The method of the present invention reduces the complexity of switching between multiple Shell processes and has good versatility and portability.
[0040] Embodiment 2
[0041] The embodiment of the present invention provides a method for implementing device operation, which is applied to embedded devices. The processing flow chart is as follows: Figure 1 As shown, the following steps are included:
[0042] Step S101, start a specified number of Shell processes.
[0043] In this step, each time a Shell process is started, if the currently started Shell process is the first Shell process started, the index value of the currently started Shell process is set as the initial index value, a second file and the first file are created, the index value of the Shell process is written into the second file and the first file respectively, the Shell process is set as the activated Shell process, and the Shell process is connected to the console " / dev / console"; otherwise, the index value in the second file is read, the updated value of the index value according to the set rule is set as the index value of the currently started Shell process, the index value of the Shell process is updated to the second file, the Shell process is set as the inactivated Shell process, and a timer is opened for the Shell process. The time intervals of the timers of all inactivated Shell processes can be equal. For example, suppose that three Shell processes are started. If Shell1 is the first Shell process started, set the index value of Shell1 to 1, create the second file and the first file, write the index value of Shell1 to the second file and the first file respectively, set Shell1 to be the activated Shell process, and establish a connection between Shell1 and the console " / dev / console". When starting Shell2, read the requested value in the second file as 1, set the index value of Shell2 to 2 according to the index value increment rule, update the index value of Shell2 to the second file, set Shell2 to be an inactivated Shell process, and start a timer for Shell2. The process of starting Shell3 is the same as that of Shell2, where the index value of Shell3 is 3, and the index value in the second file is also updated to 3, which will not be repeated here.
[0044] It should be noted that, in this embodiment, the unique identifier of the Shell process is the index value of the Shell process. In addition, the processing methods of steps S102 and S103 in the embodiment of the present invention are the same as the processing methods of steps S102 and S103 in the first embodiment, and are not repeated here.
[0045] Optionally, before any one of the specified number of Shell processes is set as the active Shell process, a user command can be input to view the index value of the Shell process currently connected to the console " / dev / console", or the maximum index value of the process in the specified number of Shell processes can be viewed, so as to obtain the optional range of the Shell process index value, thereby providing assistance for switching to the Shell process desired by the user.
[0046] This embodiment shares the index value of the activated Shell process in a file manner, so that each inactivated Shell process can determine whether it can be switched to an activated Shell process by regularly reading the file. The method of the present invention reduces the complexity of switching between multiple Shell processes and has good versatility and portability.
[0047] Embodiment 3
[0048] The embodiment of the present invention provides a device operation implementation device 20, which is applied to an embedded device, and its schematic diagram is shown as follows: Figure 2 As shown, including:
[0049] A startup module 201 is used to start a specified number of Shell processes;
[0050] The Shell process module 202 is used to select any one of the specified number of Shell processes as an active Shell process, and update the unique identifier of the activated Shell process to the first file; and to periodically read the unique identifier in the first file for any inactivated Shell process to determine whether the inactivated Shell process can be switched to an activated Shell process; if so, the inactivated Shell process is switched to an activated Shell process and establishes a connection with the console, waiting for parsing of user instructions;
[0051] The console module 203 is used to forward the input user instruction to the Shell process connected to the console for parsing and processing; and to forward the result of the parsing and processing to the Shell process connected to the console for output.
[0052] The startup module 201 is specifically used for: when a Shell process is started each time, if the Shell process currently started is the first Shell process started, creating the first file, writing the unique identifier of the Shell process into the first file, setting the Shell process as an activated Shell process, and establishing a connection between the Shell process and the console; otherwise, setting the Shell process as an inactivated Shell process and starting a timer for the Shell process. The time intervals of the timers of all inactivated Shell processes may be equal.
[0053] As another preferred embodiment of the present invention, the startup module 201 is specifically used for: each time a Shell process is started, if the Shell process currently started is the first Shell process started, setting the index value of the Shell process currently started as the initial index value, creating a second file and the first file, writing the index value of the Shell process into the second file and the first file respectively, setting the Shell process as the activated Shell process, and establishing a connection between the Shell process and the console; otherwise, reading the index value in the second file, setting the updated value of the index value according to the set rule as the index value of the Shell process currently started, updating the index value of the Shell process into the second file, setting the Shell process as the inactivated Shell process, and opening a timer for the Shell process. Wherein, the time intervals of the timers of all inactivated Shell processes can be equal.
[0054] The Shell process module 202 is specifically used for: when a user instruction is input to set any one of the specified number of Shell processes as an activated Shell process, if the unique identifier of the Shell process set as the activated Shell process is not equal to the unique identifier of the Shell process currently connected to the console, the Shell process currently connected to the console updates the unique identifier of the Shell process set as the activated Shell process into the first file, and the Shell process currently connected to the console sets itself as an inactivated Shell process, disconnects from the console, and starts the timer.
[0055] Furthermore, the Shell process module 202 is specifically used for: after the timer of any inactivated Shell process expires, the Shell process reads the unique identifier in the first file to determine whether the unique identifier of the Shell process is the same as the unique identifier in the first file; if they are the same, turning off the timer of the Shell process; otherwise, turning on the timer of the Shell process again.
[0056] This embodiment shares the unique identifier of the activated Shell process in a file mode, so that each inactivated Shell process can determine whether it can be switched to an activated Shell process by regularly reading the file. The method of the present invention reduces the complexity of switching between multiple Shell processes and has good versatility and portability.
[0057] Each part of this specification is described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the description of the method embodiment.
[0058] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A method for implementing device operation, characterized in that: Applied to an embedded device, the method comprises: Starting a specified number of Shell processes; when a user instruction is input to set any one of the specified number of Shell processes as an activated Shell process, updating the unique identifier of the activated Shell process into the first file; Any inactivated Shell process periodically reads the unique identifier in the first file to determine whether the inactivated Shell process can be switched to an activated Shell process; if so, the inactivated Shell process is switched to an activated Shell process and establishes a connection with the console, waiting for parsing of user instructions; The starting of a specified number of Shell processes includes: Each time a Shell process is started, if the Shell process currently started is the first Shell process started, the first file is created, the unique identifier of the Shell process is written into the first file, the Shell process is set as an activated Shell process, and a connection is established between the Shell process and the console; otherwise, the Shell process is set as an inactivated Shell process, and a timer is started for the Shell process.
2. The method according to claim 1, characterized in that The starting of a specified number of Shell processes includes: Each time a Shell process is started, if the Shell process currently started is the first Shell process started, the index value of the Shell process currently started is set as the initial index value, a second file and the first file are created, the index value of the Shell process is written into the second file and the first file respectively, the Shell process is set as the activated Shell process, and the Shell process is connected to the console; otherwise, the index value in the second file is read, the index value is updated according to the set rule and is set as the index value of the Shell process currently started, the index value of the Shell process is updated into the second file, the Shell process is set as the inactivated Shell process, and a timer is started for the Shell process.
3. The method according to claim 1 or 2, characterized in that When the input user instruction sets any one of the specified number of Shell processes as an activated Shell process, updating the unique identifier of the activated Shell process to the first file includes: When a user instruction is input to set any one of the specified number of Shell processes as an activated Shell process, if the unique identifier of the Shell process set as the activated Shell process is not equal to the unique identifier of the Shell process currently connected to the console, the Shell process currently connected to the console updates the unique identifier of the Shell process set as the activated Shell process into the first file, and the Shell process currently connected to the console sets itself as an inactivated Shell process, disconnects from the console, and starts the timer.
4. The method according to claim 1 or 2, characterized in that: Any of the inactivated Shell processes periodically reads the unique identifier in the first file to determine whether the inactivated Shell process can be switched to an activated Shell process, including: After the timer of any inactivated Shell process expires, the Shell process reads the unique identifier in the first file to determine whether the unique identifier of the Shell process is the same as the unique identifier in the first file; if they are the same, the timer of the Shell process is closed; otherwise, the timer of the Shell process is opened again.
5. A device for implementing device operation, characterized in that: Applied to embedded devices, the device comprises: The startup module is used to start a specified number of Shell processes; The Shell process module is used for updating the unique identifier of the activated Shell process into the first file when setting any one of the specified number of Shell processes as the activated Shell process according to the input user instruction; and for any inactivated Shell process to periodically read the unique identifier in the first file to determine whether the inactivated Shell process can be switched to the activated Shell process; if so, the inactivated Shell process is switched to the activated Shell process and establishes a connection with the console, waiting for the user instruction to be parsed and processed; The console module is used to forward the input user instructions to the Shell process connected to the console for parsing and processing; and to forward the results of the parsing and processing to the Shell process connected to the console for output; The startup module is specifically used for: Each time a Shell process is started, if the Shell process currently started is the first Shell process started, the first file is created, the unique identifier of the Shell process is written into the first file, the Shell process is set as an activated Shell process, and a connection is established between the Shell process and the console; otherwise, the Shell process is set as an inactivated Shell process, and a timer is started for the Shell process.
6. The device according to claim 5, characterized in that The startup module is specifically used for: Each time a Shell process is started, if the Shell process currently started is the first Shell process started, the index value of the Shell process currently started is set as the initial index value, a second file and the first file are created, the index value of the Shell process is written into the second file and the first file respectively, the Shell process is set as the activated Shell process, and the Shell process is connected to the console; otherwise, the index value in the second file is read, the index value is updated according to the set rule and is set as the index value of the Shell process currently started, the index value of the Shell process is updated into the second file, the Shell process is set as the inactivated Shell process, and a timer is started for the Shell process.
7. The device according to claim 5 or 6, characterized in that The Shell process module is specifically used for: When any one of the specified number of Shell processes is set as an activated Shell process according to an input user instruction, if the unique identifier of the Shell process set as the activated Shell process is not equal to the unique identifier of the Shell process currently connected to the console, the Shell process currently connected to the console updates the unique identifier of the Shell process set as the activated Shell process into the first file, and the Shell process currently connected to the console sets itself as an inactivated Shell process, disconnects from the console, and starts the timer.
8. The device according to claim 5 or 6, characterized in that The Shell process module is specifically used for: After the timer of any inactivated Shell process expires, the Shell process reads the unique identifier in the first file to determine whether the unique identifier of the Shell process is the same as the unique identifier in the first file; if they are the same, the timer of the Shell process is closed; otherwise, the timer of the Shell process is opened again.
