File tree Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Expand file tree Collapse file tree 2 files changed +8
-9
lines changed Original file line number Diff line number Diff line change @@ -6,7 +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
+ ctrlc = { version = " 3.4.2" , features = [ " termination " ] }
10
10
11
11
[[bin ]]
12
12
name = " kill_tree"
Original file line number Diff line number Diff line change 1
1
use kill_tree:: { blocking:: kill_tree_with_config, Config } ;
2
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
3
- use std:: sync:: Arc ;
2
+ use std:: sync:: mpsc:: channel;
4
3
5
4
fn cleanup_children ( ) {
6
5
let current_process_id = std:: process:: id ( ) ;
@@ -13,16 +12,16 @@ fn cleanup_children() {
13
12
}
14
13
15
14
fn main ( ) {
16
- let running = Arc :: new ( AtomicBool :: new ( true ) ) ;
17
- let r = running. clone ( ) ;
15
+ let ( tx, rx) = channel ( ) ;
18
16
19
17
ctrlc:: set_handler ( move || {
20
18
cleanup_children ( ) ;
21
- r . store ( false , Ordering :: SeqCst ) ;
19
+ tx . send ( ( ) ) . expect ( "Could not send signal on channel." ) ;
22
20
} )
23
- . expect ( "Error setting Ctrl-C handler" ) ;
21
+ . expect ( "Error setting handler. " ) ;
24
22
25
- println ! ( "Waiting for Ctrl-C..." ) ;
26
- while running. load ( Ordering :: SeqCst ) { }
23
+ println ! ( "Current process id: {}" , std:: process:: id( ) ) ;
24
+ println ! ( "Waiting for signal..." ) ;
25
+ rx. recv ( ) . expect ( "Could not receive from channel." ) ;
27
26
println ! ( "Got it! Exiting..." ) ;
28
27
}
You can’t perform that action at this time.
0 commit comments