2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Break - send a signal to a process.
9 /*****************************************************************************
15 Break <process> [ALL|C|D|E|F]
18 PROCESS/N,PORT,NAME/K,ALL/S,C/S,D/S,E/S,F/S
24 BREAK sends one or more signals to a CLI process.
25 The argument PROCESS specifies the numeric ID of the CLI process that
26 you wish to send the signal to. The STATUS command will list all currently
27 running CLI processes along with ther ID.
28 You can also specify a public port name and send signal's to the
31 You can send all signals at once via option ALL or any combination of the
32 flags CTRL-C, CTRL-D, CTRL-E and CTRL-F by their respective options.
33 When only the CLI process ID is specified the CTRL-C signal will be sent.
35 The effect of using the BREAK command is the same as selecting
36 the console window of a process and pressing the relevant key
39 The normal meaning of the keys is:
40 CTRL-C - Halt a process
41 CTRL-D - Halt a shell script
42 CTRL-E - Close a process' window
43 CTRL-F - Make active the process' window
45 Not all programs respond to these signals, however most should
52 Send the CTRL-C signal to the process numbered 1.
56 Send the CTRL-E signal to the process numbered 4.
58 1.SYS:> BREAK NAME c:dhcpclient
60 Send the CTRL-C signal to the process named "c:dhcpclient".
62 **************************************************************************/
64 #include <exec/types.h>
65 #include <exec/tasks.h>
67 #include <dos/dosextens.h>
68 #include <dos/rdargs.h>
69 #include <utility/tagitem.h>
70 #include <proto/exec.h>
71 #include <proto/dos.h>
73 #define ARG_TEMPLATE "PROCESS/N,PORT,NAME/K,C/S,D/S,E/S,F/S,ALL/S"
84 const TEXT version
[] = "$VER: Break 42.1 (8.12.2007)";
86 static const char exthelp
[] =
87 "Break: Send break signal(s) to a CLI process\n"
88 "\tPROCESS/N signal receiver's CLI process number\n"
89 "\tPORT Portname for the Process to set flags for\n"
90 "\tNAME/K Name of the process (as shown by tasklist)\n"
91 "\tC/S send CTRL-C signal\n"
92 "\tD/S send CTRL-D signal\n"
93 "\tE/S send CTRL-E signal\n"
94 "\tF/S send CTRL-F signal\n"
95 "\tALL/S send all signals\n";
97 int __nocommandline
= 1;
103 struct RDArgs
*rd
, *rda
= NULL
;
105 IPTR args
[TOTAL_ARGS
] = { NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
};
109 if ((rda
= AllocDosObject(DOS_RDARGS
, NULL
)))
111 rda
->RDA_ExtHelp
= (STRPTR
) exthelp
;
113 if ((rd
= ReadArgs(ARG_TEMPLATE
, (IPTR
*) args
, rda
)))
115 struct Process
*pr
= NULL
;
117 if (args
[ARG_PROCESS
])
118 pr
= FindCliProc(*(IPTR
*) args
[ARG_PROCESS
]);
119 else if (args
[ARG_PORT
])
121 struct MsgPort
*MyPort
;
122 if ((MyPort
= (struct MsgPort
*) FindPort((STRPTR
) args
[ARG_PORT
])) != NULL
)
124 pr
= (struct Process
*) MyPort
->mp_SigTask
;
127 else if (args
[ARG_NAME
])
129 pr
= (struct Process
*) FindTask((UBYTE
*)args
[ARG_NAME
]);
136 /* Figure out the mask of flags to send. */
139 mask
= SIGBREAKF_CTRL_C
| SIGBREAKF_CTRL_D
140 | SIGBREAKF_CTRL_E
| SIGBREAKF_CTRL_F
;
144 mask
= (args
[ARG_C
] != NULL
? SIGBREAKF_CTRL_C
: 0)
145 | (args
[ARG_D
] != NULL
? SIGBREAKF_CTRL_D
: 0)
146 | (args
[ARG_E
] != NULL
? SIGBREAKF_CTRL_E
: 0)
147 | (args
[ARG_F
]!= NULL
? SIGBREAKF_CTRL_F
: 0);
151 mask
= SIGBREAKF_CTRL_C
; /* default */
155 Signal((struct Task
*) pr
, mask
);
160 /* There is no relevant error code, OBJECT_NOT_FOUND
161 * is a filesystem error, so we can't use that... */
163 pr
= (struct Process
*) FindTask(NULL
);
165 BPTR errStream
= (pr
->pr_CES
!= NULL
)
169 if (args
[ARG_PROCESS
])
171 VFPrintf(errStream
, "Break: Process %ld does not exist.\n", (APTR
) args
[ARG_PROCESS
]);
173 else if (args
[ARG_PORT
])
175 FPrintf(errStream
, "Break: Port \"%s\" does not exist.\n", (LONG
) args
[ARG_PORT
]);
177 else if (args
[ARG_NAME
])
179 FPrintf(errStream
, "Break: Task \"%s\" does not exist.\n", (LONG
) args
[ARG_NAME
]);
183 FPuts(errStream
, "Break: Either PROCESS, PORT or NAME is required.\n");
189 } /* ReadArgs() ok */
195 FreeDosObject(DOS_RDARGS
, rda
);
202 if (error
!= 0 && error
!= -1)
204 PrintFault(error
, "Break");