File:  [OS/2 SDKs] / os2sdk / demos / examples / kill / kill.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:11 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1988, HEAD
Microsoft OS/2 SDK 03-01-1988

/*
 * Example of DosKillProcess usage.
 *
 * With DosKillProcess, any process can kill any other.  While this is a
 * powerful and versatile ability, problems can be created if a process
 * kills, say, the session manager or a copy of CMD.
 * 
 * Another danger to watch out for is that not all resources are freed
 * when a process is killed.  If the process owned any RAM semaphores
 * when it was killed, the semaphores will not be automatically freed.
 * This sometimes makes it dangerous to kill a process without knowing
 * what state the intended victim is in.  DosKillProcess is best thought
 * of, then, as a last ditch effort to get rid of an unwieldy process.
 * 
 * DosKillProcess does not actually kill the process but instead sends
 * it a termination signal.  It is possible for processes to protect
 * themselves against such signals, and once the target is in EXITLIST
 * processing, further calls to DosKillProcess have no effect
 * whatsoever.
 *
 * Invoke as "kill pid", where pid is the process id to receive the
 * kill signal. This program works protected mode only.
 *
 * To observe the operation of this program, use the "sleep" example
 * and detach it in the background. Then use kill to kill the sleep
 * program. The detach command tells you the pid of the background
 * process.
 *
 * Compile as:	cl -AL -Lp -G2 kill.c
 *
 * Created by Microsoft Corp. 1986
 */

#define INCL_DOSPROCESS

#include <os2def.h>
#include <bsedos.h>
#include <stdio.h>

main(argc, argv)
int argc;
char *argv[];
{
	PID pid;
	USHORT kill_opt = 1;
	
	/* get the process to kill from the command line */
	if(argc == 2) {
		pid = atoi(argv[1]);
	
		/* kill the process, but not its child processes */
		if(DosKillProcess(kill_opt, pid) != 0)
			printf("Unable to kill process %u\n", pid);
	}
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.