File: killprog

package info (click to toggle)
icmake 7.18.00-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 2,840 kB
  • sloc: ansic: 7,784; makefile: 3,811; sh: 319; cpp: 83
file content (61 lines) | stat: -rwxr-xr-x 1,363 bytes parent folder | download | duplicates (8)
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
#!/usr/local/bin/icmake -qi

/*
    Sample Icmake script. Kills programs; you can type 'killprog progname'
    instead of having to look up the program PID using 'ps' and then typing
    'kill -1 <PID number>'.
    
    For the installation: see the notes in the script file 'tolower'.
*/

#define VER	"1.00"
#define TMPFILE	"/tmp/killprog.out"

int kill (string prog)
{
    int
    	nkilled;
    list
    	readstat;
    list
    	psline;
    	
    system ("ps -al > " + TMPFILE);
    
    while (readstat = fgets (TMPFILE, (int) element (1, readstat)))
    {
    	psline = strtok (element (0, readstat), " \n\t");
    	if (element (12, psline) == prog)
    	{
    	    exec (P_NOCHECK, "kill", "-1", element (2, psline));
    	    exec (P_NOCHECK, "kill", "-9", element (2, psline));
    	    nkilled++;
    	}
    }
    
    system ("rm " + TMPFILE);
    return (nkilled);
}

void main (int argc, list argv)
{
    echo (0);
    
    if (argc != 2)
    {
    	printf ("\n"
    		"ICCE Program Slayer  V", VER, "\n"
    		"Copyright (c) ICCE, 1993. All rights reserved.\n"
    		"\n"
    		"Usage: killprog prog\n"
    		"Will send a 'kill -1' signal to all programs matching "
    							"'prog', followed\n"
    		"by a 'kill -9'.\n"
    		"\n");
    	exit (1);
    }
    
    printf ("Processes slayed: ", kill (element (1, argv)), "\n");
    
    exit (0);
}