diff options
author | Jesse Luehrs <doy@tozt.net> | 2017-08-27 15:50:34 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2017-08-27 15:57:27 -0400 |
commit | 06b752eeb8a1ac3057b9acf62883339bb042847a (patch) | |
tree | e2b3977b60614f062b6e9296daea3b699dcdc68b /bin/kill_focused | |
parent | a603641cbce33aa0a6706b73d4049daedbb1dd24 (diff) | |
download | conf-06b752eeb8a1ac3057b9acf62883339bb042847a.tar.gz conf-06b752eeb8a1ac3057b9acf62883339bb042847a.zip |
kill_focused should kill the whole process group
it was killing the firefox chrome process, but the content process was
continuing to run
Diffstat (limited to 'bin/kill_focused')
-rwxr-xr-x | bin/kill_focused | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/bin/kill_focused b/bin/kill_focused index b1f8d05..06010d4 100755 --- a/bin/kill_focused +++ b/bin/kill_focused @@ -6,17 +6,29 @@ use JSON; my ($sig) = @ARGV; my $pid = get_pid(); -kill $sig, $pid; +my $pgrp = get_pgrp($pid); +kill $sig, -$pgrp; sub get_pid { my $window_id = get_window_id(); die "couldn't find window" unless defined $window_id; my $prop = `xprop -id $window_id _NET_WM_PID`; + die "couldn't get pid from focused window" + if $prop =~ /not found/; chomp($prop); $prop =~ s/^_NET_WM_PID\(CARDINAL\) = //; return $prop; } +sub get_pgrp { + my ($pid) = @_; + open my $stat_fh, '<', "/proc/$pid/stat" + or die "couldn't open /proc/$pid/stat"; + my $stat = do { local $/; <$stat_fh> }; + my @f = ($stat =~ /\([^)]*\)|[^ ]+/g); + return $f[4]; +} + sub get_window_id { return find(decode_json(`i3-msg -t get_tree`))->{window}; } |