forked from strake/init
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSSignals.hs
More file actions
88 lines (77 loc) · 2.13 KB
/
PSSignals.hs
File metadata and controls
88 lines (77 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{-# OPTIONS_GHC -Wall #-}
-- got this idea from http://jonebird.com/2010/02/09/deciphering-caught-signals/
-- man 7 signal
-- #include <signal.h>
-- #include <stdio.h>
-- #include <unistd.h>
-- void trap (int sig) {
-- printf( "HUP\n");
-- }
-- struct sigaction action;
-- char cmd[256];
-- int main(int argc, char ** argv) {
-- action.sa_handler = trap;
-- sigemptyset (&action.sa_mask);
-- action.sa_flags = 0;
-- sigaction (SIGHUP, &action, NULL);
-- sprintf(cmd,"ps -o cmd,caught -p %d", getpid());
-- system(cmd);
-- }
module PSSignals
( main
, setSignals
) where
import Data.Bits
import Numeric
import Safe
import System.Environment
import Text.Groom
-- /bin/kill --list | sed -e 's/ /\n/g'
-- 1 HUP 2 INT 3 QUIT 4 ILL 5 TRAP 6 ABRT 7 BUS
-- 8 FPE 9 KILL 10 USR1 11 SEGV 12 USR2 13 PIPE 14 ALRM
-- 15 TERM 16 STKFLT 17 CHLD 18 CONT 19 STOP 20 TSTP 21 TTIN
-- 22 TTOU 23 URG 24 XCPU 25 XFSZ 26 VTALRM 27 PROF 28 WINCH
-- 29 POLL 30 PWR 31 SYS
data Signal = -- NULL |
HUP
| INT
| QUIT
| ILL
| TRAP
| ABRT
| BUS
| FPE
| KILL
| USR1
| SEGV
| USR2
| PIPE
| ALRM
| TERM
| STKFLT
| CHLD
| CONT
| STOP
| TSTP
| TTIN
| TTOU
| URG
| XCPU
| XFSZ
| VTALRM
| PROF
| WINCH
| POLL
| PWR
| SYS
deriving (Enum, Read, Show)
-- runghc PSSignals.hs 9
-- runghc PSSignals.hs 0000000188014007 0000000000000000 0000000000001000
main :: IO ()
main =
getArgs
>>= mapM_ (putStrLn . groom . setSignals . fst . headNote "main:" . readHex)
-- setSignals 0xefb
setSignals :: Integer -> [Signal]
-- setSignals i = filter (testBit i . pred . fromEnum) [HUP .. ]
setSignals i = filter (testBit i . fromEnum) [HUP .. ]