CN101630262A - Method for monitoring and controlling subprocess based on Linux system - Google Patents
Method for monitoring and controlling subprocess based on Linux system Download PDFInfo
- Publication number
- CN101630262A CN101630262A CN200910089410A CN200910089410A CN101630262A CN 101630262 A CN101630262 A CN 101630262A CN 200910089410 A CN200910089410 A CN 200910089410A CN 200910089410 A CN200910089410 A CN 200910089410A CN 101630262 A CN101630262 A CN 101630262A
- Authority
- CN
- China
- Prior art keywords
- pid
- subprocess
- file
- control script
- task
- 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
Links
Images
Abstract
The invention provides a method for monitoring and controlling a subprocess based on a Linux system, comprising the following steps of: after starting up an operation system, loading a task list, and executing tasks in the task list; building a pid document which comprises a distributed pid for the subprocess which needs to be ministered and controlled; obtaining the pid of the subprocess when an exit signal SIGCHLD of the subprocess is judged to be received; obtaining a pid document name corresponding to the pid of the subprocess when the obtained pid of the subprocess is judged to be accordance with the pid in the built pid document; obtaining a control script name in a restarted configuration document corresponding to the pid document; and executing the control script corresponding to the control script name, and generating and executing a task for restarting the subprocess. The method for monitoring and controlling the subprocess based on the Linux system can monitor and control the quit of the subprocess, realize restart of the quit subprocess, and save system resource.
Description
Technical field
The present invention relates to the process monitoring field, particularly relate to a kind of subprocess method for supervising based on (SuSE) Linux OS.
Background technology
The service subprocess is to have the program of specific function rather than the ingredient of linux kernel.The service subprocess when system bootstrap, start usually, and when (SuSE) Linux OS moves continuous service.The Init process is first process that will move after the system bootstrap, is the parent process of all service subprocesss.Common service subprocess comprises the process of sealing, file processing subprocess, management database subprocess, Email subprocess and network subprocess etc.Running into unknown problem or mistake in system's operational process can cause these service subprocess accidents to withdraw from.At this moment need artificially to start the service subprocess that these withdraw from, otherwise the process that withdraws from can not be resumed operation.
Now, the following method of general employing addresses the above problem: monitoring process is set, this monitoring process adopts the mode of uninterrupted poll to check whether the service subprocess moves, check out that a certain service subprocess does not have operation just to restart this service subprocess if monitoring process is set, idiographic flow as shown in Figure 1.Though this method can solve the problem that service subprocess accident withdraws from, adopt monitoring process that each process is carried out uninterrupted poll check and not only can expend a large amount of system resource, but also can not realize starting in real time the unexpected service subprocess that withdraws from.
Summary of the invention
In view of this, the invention provides a kind of subprocess method for supervising, can withdrawing from of subprocess be monitored, realize withdrawing from restarting of subprocess, save system resource based on (SuSE) Linux OS.
Subprocess method for supervising based on (SuSE) Linux OS provided by the invention, behind the os starting, the task in the described task list is carried out in the loading tasks tabulation, also comprises step:
A, set up the pid file of the record pid that this subprocess distributed for the subprocess that needs monitoring;
B, judgement receive the pid that obtains described subprocess when subprocess withdraws from signal SIGCHLD;
The pid that puts down in writing in the pid of C, more obtained subprocess and the pid file of foundation obtains the title of this pid file when the two is consistent;
D, obtain the control script name that restarts the described pid file name correspondence that writes down in the configuration file;
The control script of E, the described control script name correspondence of execution generates the task of restarting subprocess of also carrying out.
As from the foregoing, adopt above-mentioned steps to monitor, realize withdrawing from restarting of subprocess,, save system resource, and can realize real-time restarting with respect to the background technology polling mode to withdrawing from of subprocess.
Wherein, described steps A comprises substep:
The pid file of the subprocess correspondence that will monitor that A1, foundation start;
A2, obtain the pid of current promoter process;
A3, described pid is write corresponding pid file.
As from the foregoing, the employing above-mentioned steps can be embodied as the pid file that the subprocess foundation that need monitor comprises the pid that is distributed fast.
Wherein, the described judgement of step B receives subprocess and withdraws from signal SIGCHLD and judged by the init process;
The described pid that obtains described subprocess is obtained by the wait system function of init process transfer.
As from the foregoing, adopt above-mentioned steps can monitor the situation that withdraws from of subprocess in real time.
Wherein, the pid file storage set up of steps A is under/var/run catalogue;
Step C comprises substep:
The pid that each pid file under the pid of obtained subprocess and the/var/run catalogue is comprised compares;
When comparative result is identical, obtain described pid file name.
As from the foregoing, adopt above-mentioned steps can conveniently obtain pid for the pid file name.
Wherein, step D is described to restart configuration file stores under/etc/init.d catalogue, comprises following field at least:
Pid file name, control script name.
As from the foregoing, adopt the above-mentioned configuration file that restarts that the subprocess that need monitor can be set flexibly.
Wherein, the described task of becoming to restart of carrying out of step e comprises the substep that generates new pid file:
The pid file of E1, deletion pid file name correspondence; The pid file of the subprocess correspondence that E2, foundation restart; E3, obtain the pid of current promoter process; E4, described pid is write corresponding pid file.
As from the foregoing, adopt above-mentioned steps can delete the pid file that withdraws from subprocess, set up new pid file, help the subprocess that restarts is withdrawed from monitoring for the subprocess that restarts.
As from the foregoing, adopt above-mentioned steps to be convenient to carry out fast the task that restarts.
Preferable, also comprise after the step e: destroy the described subprocess that withdraws from according to the control script.
As from the foregoing, adopt above-mentioned steps can reduce the unnecessary wasting of resources, improve system running speed.
Description of drawings
Fig. 1 is the process flow diagram of available technology adopting monitoring process poll monitor service subprocess;
Fig. 2 is the process flow diagram of the subprocess method for supervising based on (SuSE) Linux OS provided by the invention;
Fig. 3 is the structural representation that restarts configuration file;
Fig. 4 is the pid file, restart the corresponding relation synoptic diagram of configuration file and control pin presents.
Embodiment
The flow process of the subprocess method for supervising based on (SuSE) Linux OS provided by the invention as shown in Figure 2, comprises step:
struct?init_action{
Struct init_action*next; Single linked list next pointer
Int action; The current task type
Pid_t pid; Current task pid
Char command[INIT_BUFFS_SIZE]; Current task command execution complete trails
Char terminal[CONSOLE_BUFF_SIZE]; The output control desk of current task
}。
Task in step 204, the tabulation of executing the task starts each subprocess, generate the pid file of the subprocess correspondence that needs monitor according to the control script, and be based upon/the var/run catalogue under.
Wherein, the method for building up of pid file is: obtain the pid (Process identifier) that distributes to the subprocess of current startup by calling pidof (order of linux system standard), pid is write corresponding pid file.The naming rule of pid file is self-defined title (normally task names) .pid (the suffix name of " pid " expression file in this place's naming rule).For example the subprocess of current startup is a ftp service subprocess, and the pid that distributes to ftp service subprocess when it starts is 843, and then the pid file name of this subprocess is ftp.pid, and the content of file is 843.If subprocess is the multi-process service, then the pid with each process is kept in the same pid file with space-separated.
Executed task in step 205, the deletion task list.Can avoid repeating of task like this, save system resource.
Pid in pid that withdraws from subprocess that step 208, comparison wait system function are obtained and the pid listed files in each pid file.The pid listed files is kept at/the var/run catalogue under, as shown in Figure 4.Withdraw from if both pid unanimities, explanation are the subprocesss of setting up current pid file, enter step 209.If inconsistent, enter step 206.
The control script of the control script name correspondence that step 211, execution are obtained generates restarting of task, and executing the task generates new subprocess, rebuilds corresponding pid file.The task structure body that restarts is as follows:
struct?init_action{
Struct init_action*next; Single linked list next pointer
Int action; The current task type
Pid_tpid; Current task pid
Char command[INIT_BUFFS_SIZE]; Current task command execution complete trails
Char termina l[CONSOLE_BUFF_SIZE]; The output control desk of current task
};
Wherein,
Next member is NULL;
Action member is ONCE;
Pid member is 0;
Command member is control script complete trails/script name.With the ntp subprocess is that its control script complete trails of example is :/etc/init.d/ntp.sh
Terminal member is the subprocess control desk.Be defaulted as/dev/console
Wherein, rebuild corresponding pid file and comprise step: 1, the pid file of deletion pid file name correspondence; 2, set up the pid file of the subprocess correspondence that restarts; 3, obtain the pid of current promoter process; 4, described pid is write corresponding pid file.
Among the present invention each need withdraw from corresponding one of the subprocess of monitoring and independently control script.Control script be generally held in/the etc catalogue under.The control script comprises three functional modules: start functional module, exit function module and restart function module.Call the startup functional module in the control script in the time of system start-up, call the restart function module in the control script when restarting.
Below be the compiling procedure of the control script of example explanation ntp subprocess with the ntp subprocess.
Step 1 is determined the pid file name of ntp task: ntp.pid and control script name: ntp.sh.
Step 2, the function of writing ntp control script.The control example script is as follows:
#!/bin/sh
#description:Starts?and?stops?the?ntp?daemons?\
# used?to?provide?ntp?services.
#
#pidfile:/var/run/ntp.pid
#Const
PIDPATH=/var/run
PRGNAME=ntp
SRVNAME=ntp
#Source?function?library.
./etc/init.d/vstfunc
#Check?that?ntp.conf?exists.
[-f/etc/ntp/ntp.cfg]||exit?0
#Function
start(){
#check?program
checkonly?$PRGNAME
if?[$?-eq?0];then
exit?0
fi
sleep?3
/usr/sbin/$PRGNAME
sleep?3
return$?
}
stop(){
killproc?$PRGNAME
return?$?
}
restart(){
stop
start
}
#?Select
case″$1″in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo?$″Usage:$0{start|stop|restart}″
exit?1
esac
exit?$?
Add ntp::ntp.sh to restarting under the configuration file catalogue, can the ntp subprocess be set to the subprocess that to monitor.
The above only is preferred embodiment of the present invention, and is in order to restriction the present invention, within the spirit and principles in the present invention not all, any modification of being done, is equal to replacement, improvement etc., all should be included within protection scope of the present invention.
Claims (7)
1. subprocess method for supervising based on (SuSE) Linux OS, behind the os starting, the task in the described task list is carried out in the loading tasks tabulation, it is characterized in that, also comprises step:
A, set up the pid file of the record pid that this subprocess distributed for the subprocess that needs monitoring;
B, judgement receive the pid that obtains described subprocess when subprocess withdraws from signal SIGCHLD;
The pid that puts down in writing in the pid of C, more obtained subprocess and the pid file of foundation obtains the title of this pid file when the two is consistent;
D, obtain the control script name that restarts the described pid file name correspondence that writes down in the configuration file;
The control script of E, the described control script name correspondence of execution generates the task of restarting subprocess of also carrying out.
2. method according to claim 1 is characterized in that, described steps A comprises substep:
The pid file of the subprocess correspondence that will monitor that A1, foundation start;
A2, obtain the pid of the described subprocess of current startup;
A3, described pid is write corresponding pid file.
3. method according to claim 1 is characterized in that, the described judgement of step B receives subprocess and withdraws from signal SIGCHLD and judged by the init process;
The described pid that obtains described subprocess is obtained by the wait system function of init process transfer.
4. method according to claim 1 is characterized in that,
The pid file storage that steps A is set up is under/var/run catalogue;
Step C comprises substep:
The pid that each pid file under the pid of obtained subprocess and the/var/run catalogue is comprised compares;
When comparative result is identical, obtain described pid file name.
5. according to claim 1 or 4 described methods, it is characterized in that step D is described to restart configuration file stores under/etc/init.d catalogue, comprises following field at least:
Pid file name, control script name.
6. method according to claim 1 is characterized in that, the task that the described execution of step e restarts subprocess comprises the substep that generates new pid file:
The pid file of E1, deletion pid file name correspondence;
The pid file of the subprocess correspondence that E2, foundation restart;
E3, obtain the pid of the current subprocess that restarts;
E4, described pid is write corresponding pid file.
7. method according to claim 6 is characterized in that, also comprises after the step e:
Destroy the described subprocess that withdraws from according to the control script.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN200910089410A CN101630262A (en) | 2009-07-17 | 2009-07-17 | Method for monitoring and controlling subprocess based on Linux system |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN200910089410A CN101630262A (en) | 2009-07-17 | 2009-07-17 | Method for monitoring and controlling subprocess based on Linux system |
Publications (1)
Publication Number | Publication Date |
---|---|
CN101630262A true CN101630262A (en) | 2010-01-20 |
Family
ID=41575380
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN200910089410A Pending CN101630262A (en) | 2009-07-17 | 2009-07-17 | Method for monitoring and controlling subprocess based on Linux system |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN101630262A (en) |
Cited By (20)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102981895A (en) * | 2011-09-06 | 2013-03-20 | 中国科学院声学研究所 | Virtual multi-process operation method of single-process direct frame buffer (FB) |
CN102999387A (en) * | 2012-11-09 | 2013-03-27 | 北京奇虎科技有限公司 | Process running device and method |
CN102999388A (en) * | 2012-11-09 | 2013-03-27 | 北京奇虎科技有限公司 | Process control device and method |
CN103257901A (en) * | 2013-05-29 | 2013-08-21 | 北京奇虎科技有限公司 | Distribution method of computing tasks, cloud computing platform, terminal and system |
CN103365758A (en) * | 2013-08-05 | 2013-10-23 | 北京搜狐新媒体信息技术有限公司 | Process monitoring method and system in virtualization environment |
CN103514076A (en) * | 2013-09-11 | 2014-01-15 | 深圳市共进电子股份有限公司 | Application layer process monitoring method |
CN105224395A (en) * | 2015-10-10 | 2016-01-06 | 上海斐讯数据通信技术有限公司 | A kind of process management method and system |
CN105975384A (en) * | 2016-04-28 | 2016-09-28 | 北京小米移动软件有限公司 | Distributed process monitoring method and apparatus |
CN106293979A (en) * | 2015-06-25 | 2017-01-04 | 伊姆西公司 | Detection procedure is without the method and apparatus of response |
CN106557360A (en) * | 2016-11-09 | 2017-04-05 | 青岛海信电器股份有限公司 | Task run method and device |
CN106775980A (en) * | 2016-12-15 | 2017-05-31 | 北京奇虎科技有限公司 | A kind of process ID management method, device and computer-readable medium |
CN107623581A (en) * | 2016-07-15 | 2018-01-23 | 阿里巴巴集团控股有限公司 | Service list generation method, apparatus and system, acquisition, report method and device |
CN108196982A (en) * | 2017-12-29 | 2018-06-22 | 北京诺君安信息技术股份有限公司 | A kind of LINUX system restarts the configuration method of service automatically |
US10394619B2 (en) | 2016-08-22 | 2019-08-27 | Western Digital Technologies, Inc | Signature-based service manager with dependency checking |
CN111258850A (en) * | 2020-01-13 | 2020-06-09 | 奇安信科技集团股份有限公司 | Method and device for updating software information based on Linux system |
CN111414212A (en) * | 2020-03-27 | 2020-07-14 | 中国平安财产保险股份有限公司 | Global process control method and device, computer equipment and storage medium |
CN111694616A (en) * | 2019-03-12 | 2020-09-22 | 福建天晴在线互动科技有限公司 | Method for acquiring command execution result and computer-readable storage medium |
CN112749038A (en) * | 2021-01-26 | 2021-05-04 | 北京中电兴发科技有限公司 | Method and system for realizing software watchdog in software system |
CN114281653A (en) * | 2022-03-08 | 2022-04-05 | 统信软件技术有限公司 | Application program monitoring method and device and computing equipment |
CN111258850B (en) * | 2020-01-13 | 2024-04-19 | 奇安信科技集团股份有限公司 | Method and device for updating software information based on Linux system |
-
2009
- 2009-07-17 CN CN200910089410A patent/CN101630262A/en active Pending
Cited By (31)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN102981895A (en) * | 2011-09-06 | 2013-03-20 | 中国科学院声学研究所 | Virtual multi-process operation method of single-process direct frame buffer (FB) |
CN102999387B (en) * | 2012-11-09 | 2016-06-29 | 北京奇虎科技有限公司 | Process running gear and method |
CN102999387A (en) * | 2012-11-09 | 2013-03-27 | 北京奇虎科技有限公司 | Process running device and method |
CN102999388A (en) * | 2012-11-09 | 2013-03-27 | 北京奇虎科技有限公司 | Process control device and method |
CN102999388B (en) * | 2012-11-09 | 2016-06-29 | 北京奇虎科技有限公司 | Progress control unit and method |
CN103257901A (en) * | 2013-05-29 | 2013-08-21 | 北京奇虎科技有限公司 | Distribution method of computing tasks, cloud computing platform, terminal and system |
CN103365758B (en) * | 2013-08-05 | 2016-03-16 | 北京搜狐新媒体信息技术有限公司 | Process monitoring method under a kind of virtualized environment and system |
CN103365758A (en) * | 2013-08-05 | 2013-10-23 | 北京搜狐新媒体信息技术有限公司 | Process monitoring method and system in virtualization environment |
CN103514076A (en) * | 2013-09-11 | 2014-01-15 | 深圳市共进电子股份有限公司 | Application layer process monitoring method |
CN106293979A (en) * | 2015-06-25 | 2017-01-04 | 伊姆西公司 | Detection procedure is without the method and apparatus of response |
CN106293979B (en) * | 2015-06-25 | 2019-11-15 | 伊姆西公司 | Method and apparatus of the detection procedure without response |
CN105224395A (en) * | 2015-10-10 | 2016-01-06 | 上海斐讯数据通信技术有限公司 | A kind of process management method and system |
CN105975384A (en) * | 2016-04-28 | 2016-09-28 | 北京小米移动软件有限公司 | Distributed process monitoring method and apparatus |
CN105975384B (en) * | 2016-04-28 | 2018-10-26 | 北京小米移动软件有限公司 | The monitoring method and device of distributed process |
CN107623581A (en) * | 2016-07-15 | 2018-01-23 | 阿里巴巴集团控股有限公司 | Service list generation method, apparatus and system, acquisition, report method and device |
CN107623581B (en) * | 2016-07-15 | 2020-11-24 | 阿里巴巴集团控股有限公司 | Service list generation method, device and system, and acquisition and reporting method and device |
US10394619B2 (en) | 2016-08-22 | 2019-08-27 | Western Digital Technologies, Inc | Signature-based service manager with dependency checking |
CN106557360A (en) * | 2016-11-09 | 2017-04-05 | 青岛海信电器股份有限公司 | Task run method and device |
CN106557360B (en) * | 2016-11-09 | 2020-06-16 | 海信视像科技股份有限公司 | Task running method and device |
CN106775980A (en) * | 2016-12-15 | 2017-05-31 | 北京奇虎科技有限公司 | A kind of process ID management method, device and computer-readable medium |
CN106775980B (en) * | 2016-12-15 | 2020-04-14 | 北京奇虎科技有限公司 | Process ID management method and device and computer readable medium |
CN108196982A (en) * | 2017-12-29 | 2018-06-22 | 北京诺君安信息技术股份有限公司 | A kind of LINUX system restarts the configuration method of service automatically |
CN108196982B (en) * | 2017-12-29 | 2021-12-07 | 北京诺君安信息技术股份有限公司 | Configuration method for automatic restart service of LINUX system |
CN111694616A (en) * | 2019-03-12 | 2020-09-22 | 福建天晴在线互动科技有限公司 | Method for acquiring command execution result and computer-readable storage medium |
CN111258850A (en) * | 2020-01-13 | 2020-06-09 | 奇安信科技集团股份有限公司 | Method and device for updating software information based on Linux system |
CN111258850B (en) * | 2020-01-13 | 2024-04-19 | 奇安信科技集团股份有限公司 | Method and device for updating software information based on Linux system |
CN111414212A (en) * | 2020-03-27 | 2020-07-14 | 中国平安财产保险股份有限公司 | Global process control method and device, computer equipment and storage medium |
CN112749038A (en) * | 2021-01-26 | 2021-05-04 | 北京中电兴发科技有限公司 | Method and system for realizing software watchdog in software system |
CN112749038B (en) * | 2021-01-26 | 2023-03-10 | 北京中电兴发科技有限公司 | Method and system for realizing software watchdog in software system |
CN114281653A (en) * | 2022-03-08 | 2022-04-05 | 统信软件技术有限公司 | Application program monitoring method and device and computing equipment |
CN114281653B (en) * | 2022-03-08 | 2022-07-12 | 统信软件技术有限公司 | Application program monitoring method and device and computing equipment |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN101630262A (en) | Method for monitoring and controlling subprocess based on Linux system | |
CN110515806B (en) | Probe configuration method, device, computer equipment and storage medium | |
CN111338854B (en) | Kubernetes cluster-based method and system for quickly recovering data | |
CN113296792B (en) | Storage method, device, equipment, storage medium and system | |
CN102929747A (en) | Method for treating crash dump of Linux operation system based on loongson server | |
JP2012118827A (en) | Information processing system, information processing apparatus, preparation method, program and recording medium | |
US11210132B2 (en) | Virtual machine migration in virtualization environment having different virtualization systems | |
CN110413432B (en) | Information processing method, electronic equipment and storage medium | |
CN113656142B (en) | Container group pod-based processing method, related system and storage medium | |
CN103605536A (en) | Starting method and starting device of embedded operating system and baseboard management controller | |
CN113868151A (en) | Method and device for configuring mirror image memory and computer storage medium | |
CN112612939A (en) | Crawler deployment method, system, device, equipment and storage medium | |
CN106462455B (en) | The method and apparatus that process is taken over | |
CN102467403A (en) | Software fast switching method based on progress emigration/immigration and device thereof | |
CN112199178A (en) | Cloud service dynamic scheduling method and system based on lightweight container | |
CN102262555A (en) | Method and device for loading different versions of JAVA three-party library | |
CN109710297A (en) | A kind of equipment entirety or sub-module carry out upgrading and backing method | |
CN115357198B (en) | Mounting method and device of storage volume, storage medium and electronic equipment | |
CN1276349C (en) | Method for mirror backup of cluster platform cross parallel system | |
Lianxiang et al. | Software Reconfiguration Technology for Serviceable Satellite OBDH System | |
CN110740382B (en) | Method, device, television and medium for avoiding undesired automatic restart of television | |
CN114296915A (en) | Operating system scheduling method, device, equipment and storage medium | |
Sawada et al. | An android cluster system capable of dynamic node reconfiguration | |
CN113419921A (en) | Task monitoring method, device, equipment and storage medium | |
CN114356214B (en) | Method and system for providing local storage volume for kubernetes system |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
C06 | Publication | ||
PB01 | Publication | ||
C10 | Entry into substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
C12 | Rejection of a patent application after its publication | ||
RJ01 | Rejection of invention patent application after publication |
Application publication date: 20100120 |