File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ edition.workspace = true
6
6
[dependencies ]
7
7
kill_tree = { path = " ../../libs/kill_tree" , features = [" tokio" ] }
8
8
tokio = { version = " 1.36.0" , features = [" full" ] }
9
+ ctrlc = " 3.4.2"
9
10
10
11
[[bin ]]
11
12
name = " kill_tree"
@@ -18,3 +19,7 @@ path = "src/kill_tree_sigkill.rs"
18
19
[[bin ]]
19
20
name = " kill_tree_tokio"
20
21
path = " src/kill_tree_tokio.rs"
22
+
23
+ [[bin ]]
24
+ name = " cleanup_children"
25
+ path = " src/cleanup_children.rs"
Original file line number Diff line number Diff line change
1
+ use kill_tree:: { blocking:: kill_tree_with_config, Config } ;
2
+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
3
+ use std:: sync:: Arc ;
4
+
5
+ fn cleanup_children ( ) {
6
+ let current_process_id = std:: process:: id ( ) ;
7
+ let config = Config {
8
+ include_target : false ,
9
+ ..Default :: default ( )
10
+ } ;
11
+ let result = kill_tree_with_config ( current_process_id, & config) ;
12
+ println ! ( "kill_tree_with_config: {:?}" , result) ;
13
+ }
14
+
15
+ fn main ( ) {
16
+ let running = Arc :: new ( AtomicBool :: new ( true ) ) ;
17
+ let r = running. clone ( ) ;
18
+
19
+ ctrlc:: set_handler ( move || {
20
+ cleanup_children ( ) ;
21
+ r. store ( false , Ordering :: SeqCst ) ;
22
+ } )
23
+ . expect ( "Error setting Ctrl-C handler" ) ;
24
+
25
+ println ! ( "Waiting for Ctrl-C..." ) ;
26
+ while running. load ( Ordering :: SeqCst ) { }
27
+ println ! ( "Got it! Exiting..." ) ;
28
+ }
You can’t perform that action at this time.
0 commit comments