|
|
1.1 root 1: /* 1.1.1.2 ! root 2: * Example of DosKillProcess usage. 1.1 root 3: * 1.1.1.2 ! root 4: * With DosKillProcess, any process can kill any other. While this is a 1.1 root 5: * powerful and versatile ability, problems can be created if a process 6: * kills, say, the session manager or a copy of CMD. 7: * 8: * Another danger to watch out for is that not all resources are freed 9: * when a process is killed. If the process owned any RAM semaphores 10: * when it was killed, the semaphores will not be automatically freed. 11: * This sometimes makes it dangerous to kill a process without knowing 1.1.1.2 ! root 12: * what state the intended victim is in. DosKillProcess is best thought 1.1 root 13: * of, then, as a last ditch effort to get rid of an unwieldy process. 14: * 1.1.1.2 ! root 15: * DosKillProcess does not actually kill the process but instead sends 1.1 root 16: * it a termination signal. It is possible for processes to protect 17: * themselves against such signals, and once the target is in EXITLIST 1.1.1.2 ! root 18: * processing, further calls to DosKillProcess have no effect 1.1 root 19: * whatsoever. 20: * 21: * Invoke as "kill pid", where pid is the process id to receive the 22: * kill signal. This program works protected mode only. 23: * 24: * To observe the operation of this program, use the "sleep" example 25: * and detach it in the background. Then use kill to kill the sleep 26: * program. The detach command tells you the pid of the background 27: * process. 28: * 29: * Compile as: cl -AL -Lp -G2 kill.c 30: * 1.1.1.2 ! root 31: * Created by Microsoft Corp. 1986 1.1 root 32: */ 33: 1.1.1.2 ! root 34: #define INCL_DOSPROCESS ! 35: ! 36: #include <os2def.h> ! 37: #include <bsedos.h> 1.1 root 38: #include <stdio.h> 39: 40: main(argc, argv) 41: int argc; 42: char *argv[]; 43: { 1.1.1.2 ! root 44: PID pid; ! 45: USHORT kill_opt = 1; 1.1 root 46: 47: /* get the process to kill from the command line */ 48: if(argc == 2) { 49: pid = atoi(argv[1]); 50: 51: /* kill the process, but not its child processes */ 1.1.1.2 ! root 52: if(DosKillProcess(kill_opt, pid) != 0) 1.1 root 53: printf("Unable to kill process %u\n", pid); 54: } 55: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.