The invention discloses a method and a device for monitoring a process, belonging to the technical field of computers. The method includes: the application process to the system into the process of the specified program; the specified program to the Binder driver registration notice of the death of the application process, so that when the Binder driver is identified in the application process of death, sent to the specified program of death notification; the specified program receives the notification message of death when starting the application process, realize the application process of the guardian. By injecting the designated program and adopting the Binder mechanism, the invention ensures that the designated program can sense the death of the application process in a timely and accurate manner, and realizes the daemon of the designated program to the application process. No need to create a special daemon daemon can avoid to be recycled, and the daemon state without cycle monitoring application process in the process of reducing the system resources, and improves the system performance.
【技术实现步骤摘要】
进程守护方法及装置
本专利技术涉及计算机
,特别涉及一种进程守护方法及装置。
技术介绍
终端的系统中通常会运行多个应用程序进程,不同的应用程序进程可以实现不同的功能,当某个应用程序进程死亡时,可能会对系统的正常运行造成影响,此时就需要重新启动该应用程序进程。而为了准确感知到该应用程序进程的死亡,并及时地启动该应用程序进程,可以采用进程守护技术对该应用程序进程进行监听。以第一进程和第二进程为例,第一进程创建第二进程,此时第一进程成为父进程,第二进程成为子进程,第一进程和第二进程之间建立继承关系,第二进程可以作为第一进程的守护进程。在系统运行过程中,第二进程循环监听第一进程的进程状态,根据监听的进程状态来判断第一进程是否死亡,一旦第一进程死亡,第二进程会监控到第一进程的死亡,并重新启动第一进程。在实现本专利技术的过程中,专利技术人发现现有技术至少存在以下缺陷:第二进程需要循环地监听第一进程的进程状态,占用了过多的系统资源,耗费系统性能。而且,当第一进程死亡时,系统可能会将第二进程回收,导致第二进程无法重新启动第一进程。
技术实现思路
为了解决现有技术的问题,本专利技术实施例提供了一种进程守护方法及装置。所述技术方案如下:第一方面,提供了一种进程守护方法,所述方法包括:应用程序进程向系统进程注入指定程序;所述指定程序在运行过程中,向Binder驱动程序注册对所述应用程序进程的死亡消息通知,使得当所述Binder驱动程序确定所述应用程序进程死亡时,向所述指定程序发送死亡消息通知;所述指定程序接收到所述死亡消息通知时,启动所述应用程序进程,实现对所述应用程序进程的 ...
【技术保护点】
一种进程守护方法,其特征在于,所述方法包括:应用程序进程向系统进程注入指定程序;所述指定程序在运行过程中,向Binder驱动程序注册对所述应用程序进程的死亡消息通知,使得当所述Binder驱动程序确定所述应用程序进程死亡时,向所述指定程序发送死亡消息通知;所述指定程序接收到所述死亡消息通知时,启动所述应用程序进程,实现对所述应用程序进程的守护。
【技术特征摘要】
1.一种进程守护方法,其特征在于,所述方法包括:应用程序进程向系统进程注入指定程序;所述指定程序在运行过程中,向Binder驱动程序注册对所述应用程序进程的死亡消息通知,使得当所述Binder驱动程序确定所述应用程序进程死亡时,向所述指定程序发送死亡消息通知;所述指定程序接收到所述死亡消息通知时,启动所述应用程序进程,实现对所述应用程序进程的守护。2.根据权利要求1所述的方法,其特征在于,所述应用程序进程向系统进程注入指定程序,包括:所述应用程序进程将所述指定程序拷贝到所述系统进程的内存空间中,并运行所述指定程序。3.根据权利要求1所述的方法,其特征在于,所述指定程序在运行过程中,向Binder驱动程序注册对所述应用程序进程的死亡消息通知,包括:所述指定程序向所述系统进程注册第一Binder服务;所述应用程序进程获取所述第一Binder服务的第一代理对象;所述应用程序进程通过调用所述第一代理对象,向所述指定程序发送所述应用程序进程所创建的第二Binder服务的第二代理对象;所述指定程序获取到所述第二代理对象后,向所述Binder驱动程序注册对所述第二代理对象的死亡消息通知。4.根据权利要求3所述的方法,其特征在于,所述应用程序进程获取所述第一Binder服务的第一代理对象,包括:所述应用程序进程向服务管家ServiceManager查询所述第一Binder服务,由所述ServiceManager根据预设映射表,返回所述第一Binder服务的第一代理对象,所述预设映射表中包括已注册的Binder服务以及对应的代理对象。5.根据权利要求3所述的方法,其特征在于,所述指定程序获取到所述第二代理对象后,向所述Binder驱动程序注册对所述第二代理对象的死亡消息通知,包括:所述指定程序实现死亡消息通知接口;当所述指定程序获取到所述第二代理对象后,调用关联函数,将所述第二代理对象与所述死亡消息通知接口关联,使得当所述Binder驱动程序确定所述第二代理对象死亡时,调用所述死...
【专利技术属性】
技术研发人员:谢文军,
申请(专利权)人:腾讯科技深圳有限公司,
类型:发明
国别省市:广东,44
还没有人留言评论。发表了对其他浏览者有用的留言会获得科技券。