00001
00007
00008
00009 #include <kernel.h>
00010 #include <proc.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <stdlib.h>
00014
00024 command xsh_kill(ushort stdin, ushort stdout, ushort stderr,
00025 ushort nargs, char *args[])
00026 {
00027 long pid;
00028
00029
00030 if (nargs == 2 && strncmp(args[1],"--help",6) == 0)
00031 {
00032 fprintf(stdout, "Kills a process number PID.\n");
00033 fprintf(stdout, "\t--help\t display this help and exit\n");
00034 return OK;
00035 }
00036
00037
00038 if (nargs < 2)
00039 {
00040 fprintf(stderr, "kill: missing operand\n");
00041 fprintf(stderr, "Try 'kill --help' for more information\n");
00042 return SYSERR;
00043 }
00044 if (nargs > 2)
00045 {
00046 fprintf(stderr, "kill: too many arguments\n");
00047 fprintf(stderr, "Try 'kill --help' for more information\n");
00048 return SYSERR;
00049 }
00050
00051 pid = atol(args[1]);
00052
00053
00054 if (pid == NULLPROC)
00055 {
00056 fprintf(stderr, "kill: (%d) Operation not permitted\n",pid);
00057 return SYSERR;
00058 }
00059
00060
00061 if (pid == getpid())
00062 {
00063 fprintf(stderr, "kill: Shell killed\n");
00064 sleep(2000);
00065 }
00066
00067
00068 int result = kill(pid);
00069 if (result == SYSERR)
00070 {
00071 fprintf(stderr, "kill: (%d) No such process\n",pid);
00072 }
00073
00074 return result;
00075 }