Annotation of os2sdk/demos/examples/kill/kill.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Example of DOSKILLPROCESS usage.
                      3:  *
                      4:  * With DOSKILLPROCESS, any process can kill any other.  While this is a
                      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
                     12:  * what state the intended victim is in.  DOSKILLPROCESS is best thought
                     13:  * of, then, as a last ditch effort to get rid of an unwieldy process.
                     14:  * 
                     15:  * DOSKILLPROCESS does not actually kill the process but instead sends
                     16:  * it a termination signal.  It is possible for processes to protect
                     17:  * themselves against such signals, and once the target is in EXITLIST
                     18:  * processing, further calls to DOSKILLPROCESS have no effect
                     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:  *
                     31:  * Copyright (C) Microsoft Corp. 1986
                     32:  */
                     33: 
                     34: #include <stdio.h>
                     35: #include <doscalls.h>
                     36: 
                     37: main(argc, argv)
                     38: int argc;
                     39: char *argv[];
                     40: {
                     41:        unsigned pid;
                     42:        unsigned kill_opt = 1;
                     43:        
                     44:        /* get the process to kill from the command line */
                     45:        if(argc == 2) {
                     46:                pid = atoi(argv[1]);
                     47:        
                     48:                /* kill the process, but not its child processes */
                     49:                if(DOSKILLPROCESS(kill_opt, pid) != 0)
                     50:                        printf("Unable to kill process %u\n", pid);
                     51:        }
                     52: }

unix.superglobalmegacorp.com

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