{"id":348778,"date":"2023-06-14T15:00:58","date_gmt":"2023-06-14T15:00:58","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=348778"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=348778","title":{"rendered":"<span>\u0420\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u00ab\u043f\u0430\u0434\u0435\u043d\u0438\u044f\u00bb \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u0432 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0435\u0435 24\/7 \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0430<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h2>\n<p>\u0415\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432, \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 \u0411\u0414. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u043e \u0437\u0430\u0434\u0443\u043c\u043a\u0435, \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c 24\/7, \u0447\u0442\u043e\u0431\u044b \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0411\u0414 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0432\u0435\u0436\u0430\u0439\u0448\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. <\/p>\n<p>\u041d\u043e \u0432\u043e\u0442 \u043d\u0435\u0437\u0430\u0434\u0430\u0447\u0430&#8230; \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043e\u0442\u043b\u0430\u0436\u0435\u043d, \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0430, \u043d\u043e \u0432 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0437\u0430\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e &#171;\u0431\u0430\u0445&#187; \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u043f\u0430\u043b. \u041d\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043b\u043e\u0433\u0430\u0445, \u043d\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442. \u0418 \u043a\u0430\u043a \u043b\u043e\u0432\u0438\u0442\u044c, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u0442\u043e\u0438\u0442 \u0438 \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f. \u041d\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u043d\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<h3>\u0421\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 (\u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u0447\u0435\u043c \u043e\u043d\u0438 \u0437\u0430\u043d\u044f\u0442\u044b). \u0415\u0441\u043b\u0438 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0435, \u0442\u043e \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0432 \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0435 \u0437\u0430\u0434\u0430\u0447. \u0417\u043d\u0430\u0447\u0438\u0442 \u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0435\u0441\u0442\u044c PID.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 &#8212; &#171;\u0441\u043b\u0435\u0434\u0438\u043b\u043a\u0430&#187;. \u0421\u043b\u0435\u0434\u0438\u043b\u043a\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0435\u0449\u0451 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441 \u0442\u0430\u043a\u0438\u043c PID  \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0415\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0438\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0430\u043c\u043e\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0433\u0438\u0431\u0430\u0435\u0442, \u0442\u043e \u0435\u0451 \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u044d\u0442\u043e (\u0442.\u0435. \u043d\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 PID) \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0437\u0430\u043d\u043e\u0432\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0432 \u0442\u0443\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0442.\u0435. \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0431\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0443\u0436 \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u043c \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u043e..<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0432\u0443\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0436\u0438\u0432\u0443\u0442 \u0438 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 (\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u0442.\u043d. \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0442\u0430\u043a\u0436\u0435 \u0432 \u043f\u043e\u043b\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u0430\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f)<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def proc_1(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_1: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_1 COMPLETED!\")             break         time.sleep(x)   def proc_2(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_2: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_2 COMPLETED!\")             break         time.sleep(x)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0411\u044b\u043b\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u0432\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0430\u044f \u0437\u0430 \u0441\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435, \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0436\u0438\u0432\u0451\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c &#8212; \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c. \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438  \u0435\u0441\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <strong>join<\/strong> \u0432 \u043d\u0435\u0439, \u0442\u043e \u0441\u0430\u043c\u0430 \u043e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u043a <strong>join<\/strong> \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u0441\u0442\u0430\u0442\u0438, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0439 \u0438 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0439.<\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c &#171;\u043e\u0433\u043e\u0432\u043e\u0440\u043a\u0443&#187; \u043d\u0430 Linux \u043f\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c.  <\/p>\n<p>\u0412\u043e\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f):<\/p>\n<pre><code class=\"python\"># \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 - \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f  import multiprocessing as mp import time import random import psutil import os import platform import fnmatch import signal import subprocess   class bcolors:     HEADER = '\\033[95m'     OKBLUE = '\\033[94m'     OKCYAN = '\\033[96m'     OKGREEN = '\\033[92m'     WARNING = '\\033[93m'     FAIL = '\\033[91m'     ENDC = '\\033[0m'     BOLD = '\\033[1m'     UNDERLINE = '\\033[4m'      def proc_1(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_1: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_1 COMPLETED!\")             break         time.sleep(x)   def proc_2(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_2: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_2 COMPLETED!\")             break         time.sleep(x)   def process_killer(PID_list, timepass, exclusion_list=[]):     while True:         system = platform.system()         x = random.uniform(0, timepass)         time.sleep(x)         this_process_pid = os.getpid()         this_process = psutil.Process(this_process_pid)         this_process_info_as_dict = this_process.as_dict()         parent_process_pid = this_process.ppid()         parent_process = psutil.Process(parent_process_pid)         parent_process_as_dict = parent_process.as_dict()         parent_process_children = parent_process.children(recursive=True)         child_pid_list = []         for i in range(len(parent_process_children)):             child_info_as_dict = parent_process_children[i].as_dict()             if child_info_as_dict['pid'] != this_process_pid:                 child_pid_list.append(child_info_as_dict['pid'])         child_pid_list = list(set(child_pid_list) - set(exclusion_list))         child_pid_list = list(set(child_pid_list) - set([this_process_pid]))         # for i in range(len(child_pid_list)):         #     print(f'Process_{i+1} PID: {child_pid_list[i]}')         temp_str = '\\n'.join([f'Process_{i + 1} PID: {child_pid_list[i]}' for i in range(len(child_pid_list))])         print(f\"{temp_str}\")          if len(child_pid_list) > 0:             if len(child_pid_list) > 1:                 number = random.randint(0, len(child_pid_list) - 1)             else:                 number = 0             kill_proc = psutil.Process(child_pid_list[number])             kill_process_info_as_dict = kill_proc.as_dict()             if psutil.pid_exists(kill_process_info_as_dict['pid']):                 if fnmatch.fnmatch(kill_process_info_as_dict['name'], \"python*\"):                     print(\"We kill the process with PID\", kill_process_info_as_dict['pid'])                     try:                         process = psutil.Process(kill_process_info_as_dict['pid'])                     except psutil.NoSuchProcess:                         print(f\"Process with PID {child_pid_list[number]} not found.\")                         continue                     else:                         if system == \"Windows\":                             kill_proc.kill()                         elif system == \"Linux\":                             os.kill(kill_process_info_as_dict['pid'], signal.SIGTERM)                             # os.kill(kill_process_info_as_dict['pid'],signal.SIGKILL)                             # subprocess.call([\"kill\", str(kill_process_info_as_dict['pid'])])                          print(f\"{bcolors.FAIL}Process with PID {kill_process_info_as_dict['pid']} killed.{bcolors.ENDC}\")                         child_pid_list.remove(kill_process_info_as_dict['pid'])     if __name__ == \"__main__\":     print(f'{bcolors.OKGREEN}\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b!{bcolors.ENDC}')      process_name_list = [\"process_1\", \"process_2\"]      process_1 = mp.Process(target=proc_1, kwargs={'timepass': 2, 'repeat': 30})     process_2 = mp.Process(target=proc_2, kwargs={'timepass': 3, 'repeat': 30})      process_1.start()     process_2.start()      PID_list = [process_1.pid, process_2.pid]      # process_recov = mp.Process(target=process_recovery, kwargs={'process_pid_list': PID_list})     # process_recov.start()      process_kill = mp.Process(target=process_killer,                               kwargs={'PID_list': PID_list, 'timepass': 10, 'exclusion_list': []})     process_kill.start()      PID_list.append(process_kill.pid)      system = platform.system()      while True:         if system == \"Linux\":             os.wait()         for i in range(len(PID_list)):             try:                 if psutil.pid_exists(PID_list[i]):                     pass                     # print(f'Process with PID {process_pid} is alive')                 else:                     print(f'Process with PID {PID_list[0]} is dead')                     print(f\"{bcolors.WARNING}Restoring the process{bcolors.ENDC}\")                     if PID_list[i] == PID_list[0]:                         process = mp.Process(target=proc_1, kwargs={'timepass': 2, 'repeat': 30})                     if PID_list[i] == PID_list[1]:                         process = mp.Process(target=proc_2, kwargs={'timepass': 3, 'repeat': 30})                     process.start()                     old_pid = PID_list[i]                     PID_list[i] = process.pid                      temp_str=\"\"                     for i in range(len(PID_list)):                         if  PID_list[i]==process.pid:                             temp_str += f'{bcolors.OKGREEN}Process_{i + 1} PID: {PID_list[i]}{bcolors.ENDC} (old: {old_pid})\\n'                         else:                             temp_str += f'Process_{i + 1} PID: {PID_list[i]}\\n'                     temp_str = temp_str.rstrip()                     # temp_str = '\\n'.join(                     #     [f'Process_{i + 1} PID: {PID_list[i]}' for i in range(len(PID_list))])                     print('Recovery result:\\n' + temp_str)             except:                 pass         time.sleep(0.2)          print(\"Main PID:\", os.getpid())     print(\"Process_1 PID:\", process_1.pid)     print(\"Process_2 PID:\", process_2.pid)     print(\"Process_killer PID:\", process_kill.pid)      process_1.join()     process_2.join()     process_kill.join()     # process_recov.join()     process.join()      time.sleep(5)      print(\"Program completed\") <\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439:<\/p>\n<pre><code class=\"python\"># \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 - \u0440\u0430\u0431\u043e\u0447\u0430\u044f, \u043d\u043e \u0441\u043e\u043c\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f import multiprocessing as mp import threading import time import random import psutil import os import platform import fnmatch import signal import subprocess  class bcolors:     HEADER = '\\033[95m'     OKBLUE = '\\033[94m'     OKCYAN = '\\033[96m'     OKGREEN = '\\033[92m'     WARNING = '\\033[93m'     FAIL = '\\033[91m'     ENDC = '\\033[0m'     BOLD = '\\033[1m'     UNDERLINE = '\\033[4m'  def proc_1(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_1: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_1 COMPLETED!\")             break         time.sleep(x)   def proc_2(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_2: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_2 COMPLETED!\")             break         time.sleep(x)   def process_killer(PID_list, timepass, exclusion_list=[]):     while True:         system = platform.system()         x = random.uniform(0, timepass)         time.sleep(x)         this_process_pid = os.getpid()         this_process = psutil.Process(this_process_pid)         this_process_info_as_dict = this_process.as_dict()         parent_process_pid = this_process.ppid()         parent_process = psutil.Process(parent_process_pid)         parent_process_as_dict = parent_process.as_dict()         parent_process_children = parent_process.children(recursive=True)         child_pid_list = []         for i in range(len(parent_process_children)):             child_info_as_dict = parent_process_children[i].as_dict()             if child_info_as_dict['pid'] != this_process_pid:                 child_pid_list.append(child_info_as_dict['pid'])         child_pid_list = list(set(child_pid_list) - set(exclusion_list))         # for i in range(len(child_pid_list)):         #     print(f'Process_{i+1} PID: {child_pid_list[i]}')         temp_str = '\\n'.join([f'Process_{i + 1} PID: {child_pid_list[i]}' for i in range(len(child_pid_list))])         print(f\"{temp_str}\")          if len(child_pid_list) > 0:             if len(child_pid_list) > 1:                 number = random.randint(0, len(child_pid_list) - 1)             else:                 number = 0             kill_proc = psutil.Process(child_pid_list[number])             kill_process_info_as_dict = kill_proc.as_dict()             if psutil.pid_exists(kill_process_info_as_dict['pid']):                 if fnmatch.fnmatch(kill_process_info_as_dict['name'], \"python*\"):                     print(\"We kill the process with PID\", kill_process_info_as_dict['pid'])                     try:                         process = psutil.Process(kill_process_info_as_dict['pid'])                     except psutil.NoSuchProcess:                         print(f\"Process with PID {child_pid_list[number]} not found.\")                         continue                     else:                         if system == \"Windows\":                             kill_proc.kill()                         elif system == \"Linux\":                             os.kill(kill_process_info_as_dict['pid'], signal.SIGTERM)                             # os.kill(kill_process_info_as_dict['pid'],signal.SIGKILL)                             # subprocess.call([\"kill\", str(kill_process_info_as_dict['pid'])])                          print(f\"{bcolors.FAIL}Process with PID {kill_process_info_as_dict['pid']} killed.{bcolors.ENDC}\")                         child_pid_list.remove(kill_process_info_as_dict['pid'])   def process_recovery(process_pid_list):     PID_list = process_pid_list     this_process_pid = os.getpid()     this_process = psutil.Process(this_process_pid)     this_process_info_as_dict = this_process.as_dict()     parent_process_pid = this_process.ppid()     parent_process = psutil.Process(parent_process_pid)     parent_process_as_dict = parent_process.as_dict()     parent_process_children = parent_process.children(recursive=True)     child_pid_list = []     for i in range(len(parent_process_children)):         child_info_as_dict = parent_process_children[i].as_dict()         if child_info_as_dict['pid'] != this_process_pid:             child_pid_list.append(child_info_as_dict['pid'])      system = platform.system()      while True:         if system == \"Linux\":             try:                 os.wait()             except:                 pass         for i in range(len(child_pid_list)):             try:                 if psutil.pid_exists(child_pid_list[i]):                     pass                     # print(f'Process with PID {process_pid} is alive')                 else:                     print(f'Process with PID {child_pid_list[i]} is dead')                     print(f\"{bcolors.WARNING}Restoring the process{bcolors.ENDC}\")                     if child_pid_list[i] == PID_list[0]:                         process = mp.Process(target=proc_1, kwargs={'timepass': 2, 'repeat': 30})                     elif child_pid_list[i] == PID_list[1]:                         process = mp.Process(target=proc_2, kwargs={'timepass': 3, 'repeat': 30})                     else:                         process = mp.Process(target=process_killer,                                                   kwargs={'PID_list': PID_list, 'timepass': 10,                                                           'exclusion_list': [process_recov.pid, ]})                     process.start()                     old_pid = child_pid_list[i]                     child_pid_list[i] = process.pid                     if old_pid == PID_list[0]:                         PID_list[0] = process.pid                     if old_pid == PID_list[1]:                         PID_list[1] = process.pid                      temp_str = \"\"                     for i in range(len(child_pid_list)):                         if child_pid_list[i] == process.pid:                             temp_str += f'{bcolors.OKGREEN}Process_{i + 1} PID: {child_pid_list[i]}{bcolors.ENDC} (old: {old_pid})\\n'                         else:                             temp_str += f'Process_{i + 1} PID: {child_pid_list[i]}\\n'                     temp_str = temp_str.rstrip()                     # temp_str = '\\n'.join(                     #     [f'Process_{i + 1} PID: {PID_list[i]}' for i in range(len(PID_list))])                     print('Recovery result:\\n' + temp_str)                     threading.Thread(target=process.join).start()             except:                 pass         time.sleep(0.2)   if __name__ == \"__main__\":     process_name_list = [\"process_1\", \"process_2\"]      process_1 = mp.Process(target=proc_1, kwargs={'timepass': 2, 'repeat': 30})     process_2 = mp.Process(target=proc_2, kwargs={'timepass': 3, 'repeat': 30})      process_1.start()     process_2.start()      PID_list = [process_1.pid, process_2.pid]      process_recov = mp.Process(target=process_recovery, kwargs={'process_pid_list': PID_list})     process_recov.start()      process_kill = mp.Process(target=process_killer,                               kwargs={'PID_list': PID_list, 'timepass': 10, 'exclusion_list': [process_recov.pid, ]})     #process_kill.start()        print(\"Main PID:\", os.getpid())     print(\"Process_1 PID:\", process_1.pid)     print(\"Process_2 PID:\", process_2.pid)     print(\"Process_killer PID:\", process_kill.pid)      process_1.join()     process_2.join()     #process_kill.join()     process_recov.join()      time.sleep(5)      print(\"Program completed\") <\/code><\/pre>\n<p>\u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u0447\u0442\u043e, \u0435\u0441\u043b\u0438 \u0432\u0434\u0440\u0443\u0433, \u0432\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0451\u0442\u0435\u0441\u044c \u0441 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 \u0438 \u043d\u0435 \u0437\u0430\u0445\u043e\u0442\u0438\u0442\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u0440\u0435\u043c\u044f \u043d\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0448\u0438\u0431\u043a\u0438 &#8212; \u0444\u0430\u043d\u0442\u043e\u043c\u0430, \u0442\u043e \u0432\u0430\u043c \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0442\u0430\u043a\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/741774\/\"> https:\/\/habr.com\/ru\/articles\/741774\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<h2>\u041f\u043e\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b<\/h2>\n<p>\u0415\u0441\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u0431\u043e\u0440\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u043e\u0432, \u0438\u0445 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 \u0411\u0414. \u041f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u043e \u0437\u0430\u0434\u0443\u043c\u043a\u0435, \u0434\u043e\u043b\u0436\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c 24\/7, \u0447\u0442\u043e\u0431\u044b \u0432 \u043b\u044e\u0431\u043e\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u0411\u0414 \u0438 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0432\u0435\u0436\u0430\u0439\u0448\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. <\/p>\n<p>\u041d\u043e \u0432\u043e\u0442 \u043d\u0435\u0437\u0430\u0434\u0430\u0447\u0430&#8230; \u0412\u0440\u043e\u0434\u0435 \u0431\u044b \u0432\u0435\u0441\u044c \u043a\u043e\u0434 \u043e\u0442\u043b\u0430\u0436\u0435\u043d, \u0440\u0430\u0431\u043e\u0442\u0430 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u0430, \u043d\u043e \u0432 \u043a\u0430\u043a\u0438\u0435-\u0442\u043e \u043c\u043e\u043c\u0435\u043d\u0442\u044b \u0437\u0430\u043c\u0435\u0447\u0430\u0435\u0442\u0441\u044f, \u0447\u0442\u043e &#171;\u0431\u0430\u0445&#187; \u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043f\u0440\u043e\u043f\u0430\u043b. \u041d\u0438 \u043e\u0448\u0438\u0431\u043a\u0438 \u0432 \u043b\u043e\u0433\u0430\u0445, \u043d\u0438 \u0441\u0438\u0433\u043d\u0430\u043b\u043e\u0432, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435\u0442. \u0418 \u043a\u0430\u043a \u043b\u043e\u0432\u0438\u0442\u044c, \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u043e\u043d\u044f\u0442\u043d\u043e, \u0430 \u0440\u0430\u0431\u043e\u0442\u0430 \u0441\u0442\u043e\u0438\u0442 \u0438 \u043d\u0430\u0434\u043e \u043a\u0430\u043a-\u0442\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c\u0441\u044f. \u041d\u0430 \u043e\u0442\u043b\u0430\u0434\u043a\u0443 \u043d\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438.<\/p>\n<h3>\u0421\u0438\u043c\u0443\u043b\u044f\u0446\u0438\u044f<\/h3>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0435\u0441\u0442\u044c \u0434\u0432\u0435 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 (\u043d\u0435 \u0432\u0430\u0436\u043d\u043e, \u0447\u0435\u043c \u043e\u043d\u0438 \u0437\u0430\u043d\u044f\u0442\u044b). \u0415\u0441\u043b\u0438 \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e \u043c\u0443\u043b\u044c\u0442\u0438\u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0438\u043d\u0433\u0435, \u0442\u043e \u043c\u044b \u0433\u043e\u0432\u043e\u0440\u0438\u043c, \u0447\u0442\u043e \u043a\u0430\u0436\u0434\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e, \u043a\u0430\u043a \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0430\u044f \u0437\u0430\u0434\u0430\u0447\u0430, \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043c\u043e\u0436\u043d\u043e \u0432 \u0414\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0435 \u0437\u0430\u0434\u0430\u0447. \u0417\u043d\u0430\u0447\u0438\u0442 \u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u0435\u0441\u0442\u044c PID.<\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c, \u0447\u0442\u043e \u0442\u0440\u0435\u0442\u0438\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 &#8212; &#171;\u0441\u043b\u0435\u0434\u0438\u043b\u043a\u0430&#187;. \u0421\u043b\u0435\u0434\u0438\u043b\u043a\u0430 \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043e\u043d\u0430 \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0435\u0449\u0451 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441 \u0442\u0430\u043a\u0438\u043c PID  \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435. \u0415\u0441\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0437\u0430\u0432\u0435\u0440\u0448\u0430\u0435\u0442\u0441\u044f \u0438\u043b\u0438 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0441\u0430\u043c\u043e\u043f\u0440\u043e\u0438\u0437\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u043e\u0433\u0438\u0431\u0430\u0435\u0442, \u0442\u043e \u0435\u0451 \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u044d\u0442\u043e (\u0442.\u0435. \u043d\u0435 \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 PID) \u0438 \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c \u043f\u0440\u043e\u0446\u0435\u0441\u0441, \u0437\u0430\u043d\u043e\u0432\u043e \u043f\u043e\u043c\u0435\u0441\u0442\u0438\u0432 \u0442\u0443\u0434\u0430 \u0444\u0443\u043d\u043a\u0446\u0438\u044e.<\/p>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0447\u0442\u043e \u043d\u0443\u0436\u043d\u043e \u0438\u043c\u0438\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430, \u0442.\u0435. \u0434\u043e\u043b\u0436\u043d\u0430 \u0431\u044b\u0442\u044c \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0438\u0441\u043a\u0443\u0441\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0443\u0431\u0438\u0432\u0430\u0435\u0442 \u043f\u0440\u043e\u0446\u0435\u0441\u0441.<\/p>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f, \u0447\u0442\u043e\u0431\u044b \u0443\u0436 \u0431\u044b\u0442\u044c \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u043f\u0440\u0438\u0431\u043b\u0438\u0436\u0435\u043d\u043d\u044b\u043c \u043a \u0440\u0435\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u043d\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0436\u0434\u0443 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438, \u0447\u0442\u043e\u0431\u044b \u0432\u0441\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0438 \u0430\u0432\u0442\u043e\u043d\u043e\u043c\u043d\u043e..<\/p>\n<h2>\u0420\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/h2>\n<p>\u0412\u043e\u0442 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u0432\u0443\u0445 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0436\u0438\u0432\u0443\u0442 \u0438 \u0447\u0442\u043e-\u0442\u043e \u0434\u0435\u043b\u0430\u044e\u0442 (\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0441\u043a\u0440\u044b\u0442\u044b\u0439 \u0442\u0435\u043a\u0441\u0442, \u0442.\u043d. \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0442\u0430\u043a\u0436\u0435 \u0432 \u043f\u043e\u043b\u043d\u044b\u0445 \u0442\u0435\u043a\u0441\u0442\u0430\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f)<\/p>\n<details class=\"spoiler\">\n<summary>Hidden text<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">def proc_1(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_1: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_1 COMPLETED!\")             break         time.sleep(x)   def proc_2(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_2: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_2 COMPLETED!\")             break         time.sleep(x)<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0411\u044b\u043b\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u0432\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u0444\u0443\u043d\u043a\u0446\u0438\u044f, \u043e\u0442\u0432\u0435\u0447\u0430\u044e\u0449\u0430\u044f \u0437\u0430 \u0441\u043b\u0435\u0436\u0435\u043d\u0438\u0435 \u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u0435, \u0432 \u043f\u0435\u0440\u0432\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435, \u0436\u0438\u0432\u0451\u0442 \u0432 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u0430 \u0432\u043e \u0432\u0442\u043e\u0440\u043e\u043c &#8212; \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c. \u0412\u0442\u043e\u0440\u043e\u0439 \u0441\u043b\u0443\u0447\u0430\u0439 \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u0435\u043c, \u0447\u0442\u043e \u043f\u0435\u0440\u0435\u0437\u0430\u043f\u0443\u0441\u043a \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u0438\u0437 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u0438  \u0435\u0441\u043b\u0438 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u0442\u044c <strong>join<\/strong> \u0432 \u043d\u0435\u0439, \u0442\u043e \u0441\u0430\u043c\u0430 \u043e\u043d\u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u0443\u0434\u0435\u0442 \u0436\u0434\u0430\u0442\u044c. \u0420\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u044d\u0442\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u044f\u0432\u0438\u043b\u043e\u0441\u044c \u0437\u0430\u043f\u0443\u0441\u043a <strong>join<\/strong> \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u043e\u043c \u043f\u043e\u0442\u043e\u043a\u0435.<\/p>\n<p>\u0412\u0442\u043e\u0440\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043a\u0441\u0442\u0430\u0442\u0438, \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043f\u0440\u0438\u044f\u0442\u043d\u0435\u0439 \u0438 \u043b\u043e\u0433\u0438\u0447\u043d\u0435\u0439.<\/p>\n<p>\u041e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u043c \u043c\u043e\u043c\u0435\u043d\u0442\u043e\u043c \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e\u0433\u043e, \u0432 \u043a\u0430\u043a\u043e\u0439 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u043e\u0439 \u0441\u0438\u0441\u0442\u0435\u043c\u0435 \u0432\u044b \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0435 \u0440\u0430\u0431\u043e\u0442\u0443 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u041f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0434\u0435\u043b\u0430\u0442\u044c &#171;\u043e\u0433\u043e\u0432\u043e\u0440\u043a\u0443&#187; \u043d\u0430 Linux \u043f\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u043c \u043f\u0440\u0438\u0447\u0438\u043d\u0430\u043c.  <\/p>\n<p>\u0412\u043e\u0442 \u043f\u0435\u0440\u0432\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u043f\u043e\u043b\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0440\u0435\u0448\u0435\u043d\u0438\u044f):<\/p>\n<pre><code class=\"python\"># \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 - \u0440\u0430\u0431\u043e\u0447\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f  import multiprocessing as mp import time import random import psutil import os import platform import fnmatch import signal import subprocess   class bcolors:     HEADER = '\\033[95m'     OKBLUE = '\\033[94m'     OKCYAN = '\\033[96m'     OKGREEN = '\\033[92m'     WARNING = '\\033[93m'     FAIL = '\\033[91m'     ENDC = '\\033[0m'     BOLD = '\\033[1m'     UNDERLINE = '\\033[4m'      def proc_1(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_1: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_1 COMPLETED!\")             break         time.sleep(x)   def proc_2(timepass=1, repeat=20):     repeated = True     i = 0     while repeated:         x = random.uniform(0, timepass)         i += 1         if i &lt; repeat:             print(\"Proc_2: \" + str(i) + \", will fall asleep for: \" + str(x))         else:             repeated = False             print(\"Proc_2 COMPLETED!\")             break         time.sleep(x)   def process_killer(PID_list, timepass, exclusion_list=[]):     while True:         system = platform.system()         x = random.uniform(0, timepass)         time.sleep(x)         this_process_pid = os.getpid()         this_process = psutil.Process(this_process_pid)         this_process_info_as_dict = this_process.as_dict()         parent_process_pid = this_process.ppid()         parent_process = psutil.Process(parent_process_pid)         parent_process_as_dict = parent_process.as_dict()         parent_process_children = parent_process.children(recursive=True)         child_pid_list = []         for i in range(len(parent_process_children)):             child_info_as_dict = parent_process_children[i].as_dict()             if child_info_as_dict['pid'] != this_process_pid:                 child_pid_list.append(child_info_as_dict['pid'])         child_pid_list = list(set(child_pid_list) - set(exclusion_list))         child_pid_list = list(set(child_pid_list) - set([this_process_pid]))         # for i in range(len(child_pid_list)):         #     print(f'Process_{i+1} PID: {child_pid_list[i]}')         temp_str = '\\n'.join([f'Process_{i + 1} PID: {child_pid_list[i]}' for i in range(len(child_pid_list))])         print(f\"{temp_str}\")          if len(child_pid_list) > 0:             if len(child_pid_list) > 1:                 number = random.randint(0, len(child_pid_list) - 1)             else:                 number = 0             kill_proc = psutil.Process(child_pid_list[number])             kill_process_info_as_dict = kill_proc.as_dict()             if psutil.pid_exists(kill_process_info_as_dict['pid']):                 if fnmatch.fnmatch(kill_process_info_as_dict['name'], \"python*\"):                     print(\"We kill the process with PID\", kill_process_info_as_dict['pid'])                     try:                         process = psutil.Process(kill_process_info_as_dict['pid'])                     except psutil.NoSuchProcess:                         print(f\"Process with PID {child_pid_list[number]} not found.\")                         continue                     else:                         if system == \"Windows\":                             kill_proc.kill()                         elif system == \"Linux\":                             os.kill(kill_process_info_as_dict['pid'], signal.SIGTERM)                             # os.kill(kill_process_info_as_dict['pid'],signal.SIGKILL)                             # subprocess.call([\"kill\", str(kill_process_info_as_dict['pid'])])                          print(f\"{bcolors.FAIL}Process with PID {kill_process_info_as_dict['pid']} killed.{bcolors.ENDC}\")                         child_pid_list.remove(kill_process_info_as_dict['pid'])     if __name__ == \"__main__\":     print(f'{bcolors.OKGREEN}\u041d\u0430\u0447\u0430\u043b\u043e \u0440\u0430\u0431\u043e\u0442\u044b \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b!{bcolors.ENDC}')      process_name_list = [\"process_1\", \"process_2\"]      process_1 = mp.Process(target=proc_1, kwargs={'timepass': 2, 'repeat': 30})     process_2 = mp.Process(target=proc_2, kwargs={'timepass': 3, 'repeat': 30})      process_1.start()     process_2.start()      PID_list = [process_1.pid, process_2.pid]      # process_recov = mp.Process(target=process_recovery, kwargs={'process_pid_list': PID_list})     # process_recov.start()      process_kill = mp.Process(target=process_killer,                               kwargs={'PID_list': PID_list, 'timepass': 10, 'exclusion_list': []})     process_kill.start()      PID_list.append(process_kill.pid)      system = platform.system()      while True:         if system == \"Linux\":             os.wait()         for i in range(len(PID_list)):             try:                 if psutil.pid_exists(PID_list[i]):                     pass                     # print(f'Process with PID {process_pid} is alive')                 else:                     print(f'Process with PID {PID_list[0]} is dead')                     print(f\"{bcolors.WARNING}Restoring the process{bcolors.ENDC}\")                     if PID_list[i] == PID_list[0]:                         process = mp.Process(target=proc_1, kwargs={'timepass': 2, 'repeat': 30})                     if PID_list[i] == PID_list[1]:                         process = mp.Process(target=proc_2, kwargs={'timepass': 3, 'repeat': 30})                     process.start()                     old_pid = PID_list[i]                     PID_list[i] = process.pid                      temp_str=\"\"                     for i in range(len(PID_list)):                         if  PID_list[i]==process.pid:                             temp_str += f'{bcolors.OKGREEN}Process_{i + 1} PID: {PID_list[i]}{bcolors.ENDC} (old: {old_pid})\\n'                         else:                             temp_str += f'Process_{i + 1} PID: {PID_list[i]}\\n'                     temp_str = temp_str.rstrip()                     # temp_str = '\\n'.join(                     #     [f'Process_{i + 1} PID: {PID_list[i]}' for i in range(len(PID_list))])                     print('Recovery result:\\n' + temp_str)             except:                 pass         time.sleep(0.2)          print(\"Main PID:\", os.getpid())     print(\"Process_1 PID:\", process_1.pid)     print(\"Process_2 PID:\", process_2.pid)     print(\"Process_killer PID:\", process_kill.pid)      process_1.join()     process_2.join()     process_kill.join()     # process_recov.join()     process.join()      time.sleep(5)      print(\"Program completed\") <\/code><\/pre>\n<p>\u0410 \u0432\u043e\u0442 \u0432\u0442\u043e\u0440\u043e\u0439:<\/p>\n<pre><code class=\"python\"># \u0420\u0430\u0431\u043e\u0442\u0430 \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0430\u043c\u0438 - \u0440\u0430\u0431\u043e\u0447\u0430\u044f, \u043d\u043e \u0441\u043e\u043c\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f import multiprocessing as mp import threading import time import random import psutil import os import platform import fnmatch import signal import subprocess  class bcolors:     HEADER = '\\033[95m'     OKBLUE = '\\033[94m'     OKCYAN = '\\033[96m'     OKGREEN = '\\033[92m'     WARNING = <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-348778","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348778","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=348778"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/348778\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=348778"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=348778"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=348778"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}