1235368Sgnn#!/usr/sbin/dtrace -qs
2235368Sgnn/*
3235368Sgnn * kill.d - watch process signals as they are sent (eg, kill -9).
4235368Sgnn *          Written in DTrace (Solaris 10 3/05).
5235368Sgnn *
6235368Sgnn * $Id: kill.d 3 2007-08-01 10:50:08Z brendan $
7235368Sgnn *
8235368Sgnn * USAGE:       kill.d
9235368Sgnn *
10235368Sgnn * FIELDS:
11235368Sgnn *              FROM     source PID
12235368Sgnn *              COMMAND  source command name
13235368Sgnn *              TO       destination PID
14235368Sgnn *              SIG      destination signal ("9" for a kill -9)
15235368Sgnn *              RESULT   result of signal (-1 is for failure)
16235368Sgnn *
17235368Sgnn * SEE ALSO: Chapter 25, Solaris Dynamic Tracing Guide, docs.sun.com,
18235368Sgnn *           for a solution using proc:::signal-send.
19235368Sgnn *
20235368Sgnn * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
21235368Sgnn *
22235368Sgnn * CDDL HEADER START
23235368Sgnn *
24235368Sgnn *  The contents of this file are subject to the terms of the
25235368Sgnn *  Common Development and Distribution License, Version 1.0 only
26235368Sgnn *  (the "License").  You may not use this file except in compliance
27235368Sgnn *  with the License.
28235368Sgnn *
29235368Sgnn *  You can obtain a copy of the license at Docs/cddl1.txt
30235368Sgnn *  or http://www.opensolaris.org/os/licensing.
31235368Sgnn *  See the License for the specific language governing permissions
32235368Sgnn *  and limitations under the License.
33235368Sgnn *
34235368Sgnn * CDDL HEADER END
35235368Sgnn *
36235368Sgnn * 09-May-2004  Brendan Gregg   Created this.
37235368Sgnn * 28-Jun-2005	   "      "	Last update.
38235368Sgnn */
39235368Sgnn
40235368Sgnndtrace:::BEGIN
41235368Sgnn{
42235368Sgnn	/* Print header */
43235368Sgnn	printf("%5s %12s %5s %-6s %s\n",
44235368Sgnn	    "FROM", "COMMAND", "SIG", "TO", "RESULT");
45235368Sgnn}
46235368Sgnn
47235368Sgnnsyscall::kill:entry
48235368Sgnn{
49235368Sgnn	/* Record target PID and signal */
50235368Sgnn	self->target = arg0;
51235368Sgnn	self->signal = arg1;
52235368Sgnn}
53235368Sgnn
54235368Sgnnsyscall::kill:return
55235368Sgnn{
56235368Sgnn	/* Print source, target, and result */
57235368Sgnn	printf("%5d %12s %5d %-6d %d\n",
58235368Sgnn	    pid, execname, self->signal, self->target, (int)arg0);
59235368Sgnn
60235368Sgnn	/* Cleanup memory */
61235368Sgnn	self->target = 0;
62235368Sgnn	self->signal = 0;
63235368Sgnn}
64