Problem
Given n processes, each process has a unique PID (process id) and its PPID (parent process id).
Each process only has one parent process, but may have one or more children processes. This is just like a tree structure. Only one process has PPID that is 0, which means this process has no parent process. All the PIDs will be distinct positive integers.
We use two list of integers to represent a list of processes, where the first list contains PID for each process and the second list contains the corresponding PPID.
Now given the two lists, and a PID representing a process you want to kill, return a list of PIDs of processes that will be killed in the end. You should assume that when a process is killed, all its children processes will be killed. No order is required for the final answer.
ExampleExample 1:
Input:
pid = [1, 3, 10, 5]
ppid = [3, 0, 5, 3]
kill = 5
Output: [5,10]
Explanation:
3 / 1 5 / 10
Kill 5 will also kill 10.
Note:
The given kill id is guaranteed to be one of the given PIDs.
n >= 1.
class Solution { public ListkillProcess(List pid, List ppid, int kill) { List res = new ArrayList<>(); if (pid == null || pid.size() == 0) return res; Map > map = new HashMap<>(); for (Integer id: pid) { map.put(id, new HashSet ()); } for (int i = 0; i < ppid.size(); i++) { int id = ppid.get(i); if (map.containsKey(id)) { map.get(id).add(pid.get(i)); } } traverse(kill, map, res); return res; } public void traverse(int kill, Map > map, List res) { res.add(kill); Set children = map.get(kill); for (Integer child: children) { traverse(child, map, res); } } }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/76791.html
小編寫這篇文章的目的,主要是給大家講解一下,關(guān)于實(shí)現(xiàn)配置熱加載的方法,具體是怎么操作呢?下面就給大家詳細(xì)的解答下?! ”尘啊 ∮捎谧罱邢嚓P(guān)的工作需求,需要進(jìn)行增添相關(guān)的新功能,實(shí)現(xiàn)配置熱加載的功能。所謂的配置熱加載,也就是說(shuō)當(dāng)服務(wù)收到配置更新消息之后,我們不用重啟服務(wù)就可以使用最新的配置去執(zhí)行任務(wù)。 如何實(shí)現(xiàn) 下面我分別采用多進(jìn)程、多線程、協(xié)程的方式去實(shí)現(xiàn)配置熱加載?! ∈褂枚噙M(jìn)程實(shí)現(xiàn)配...
摘要:被設(shè)計(jì)為這樣一種方式,父進(jìn)程必須明確地等待子進(jìn)程終止,以便收集它的退出狀態(tài)。會(huì)完成的刪除,將優(yōu)雅退出的時(shí)間設(shè)置為表示立即刪除。 SIGINT SIGTERM SIGKILL區(qū)別 三者都是結(jié)束/終止進(jìn)程運(yùn)行。 1.SIGINT SIGTERM區(qū)別 前者與字符ctrl+c關(guān)聯(lián),后者沒(méi)有任何控制字符關(guān)聯(lián)。前者只能結(jié)束前臺(tái)進(jìn)程,后者則不是。 2.SIGTERM SIGKILL的區(qū)別 前者可以被...
摘要:被設(shè)計(jì)為這樣一種方式,父進(jìn)程必須明確地等待子進(jìn)程終止,以便收集它的退出狀態(tài)。會(huì)完成的刪除,將優(yōu)雅退出的時(shí)間設(shè)置為表示立即刪除。 SIGINT SIGTERM SIGKILL區(qū)別 三者都是結(jié)束/終止進(jìn)程運(yùn)行。 1.SIGINT SIGTERM區(qū)別 前者與字符ctrl+c關(guān)聯(lián),后者沒(méi)有任何控制字符關(guān)聯(lián)。前者只能結(jié)束前臺(tái)進(jìn)程,后者則不是。 2.SIGTERM SIGKILL的區(qū)別 前者可以被...
摘要:熱部署,就是在應(yīng)用正在運(yùn)行的時(shí)候升級(jí)軟件,卻不需要重新啟動(dòng)應(yīng)用。熱部署的流程是備份舊的可執(zhí)行文件新的可執(zhí)行文件直接替換舊的此時(shí)舊的進(jìn)程還在運(yùn)行向進(jìn)程發(fā)送熱部署信號(hào),新的進(jìn)程啟動(dòng),舊的不再就收請(qǐng)求。關(guān)閉舊的進(jìn)程,完成熱部署。 熱部署,就是在應(yīng)用正在運(yùn)行的時(shí)候升級(jí)軟件,卻不需要重新啟動(dòng)應(yīng)用。 首先在本地模擬一個(gè)線上需要升級(jí) Nginx 的環(huán)境,假設(shè)舊版本為 nginx-1.0.15,需要升...
閱讀 2002·2021-11-22 14:44
閱讀 1746·2021-11-02 14:46
閱讀 3836·2021-10-13 09:40
閱讀 2675·2021-09-07 09:58
閱讀 1796·2021-09-03 10:28
閱讀 1719·2019-08-29 15:30
閱讀 1044·2019-08-29 15:28
閱讀 1539·2019-08-26 12:20