/*-------------------------------------------------------------------*/ /* testkill.c */ /* The kill system call. */ /*-------------------------------------------------------------------*/ #include #include #include #include #include /* The kill function should be declared in unistd.h, but is not. So we must declare it explicitly. */ int kill(pid_t iPid, int iSignal); int main(int argc, char *argv[]) { int i = 0; int iPid; int iRet; printf("Parent process (%ld)\n", (long)getpid()); fflush(NULL); iPid = fork(); if (iPid == -1) {perror(argv[0]); return 1; } if (iPid == 0) { /* This code is executed by only the child process. */ while (1) { printf("Child process (%ld): %d\n", (long)getpid(), i); i++; } exit(0); /* Should never reach. */ } /* Sleep for 1 second. */ sleep(1); iRet = kill(iPid, SIGKILL); if (iRet == -1) {perror(argv[0]); return 1; } return 0; } /* Sample execution: $ gcc -Wall -ansi -pedantic -o testkill testkill.c $ testkill Parent process (29497) Child process (29498): 0 ... Child process (29498): 1918 Child process (29498): 1919 Child process (29498): 1920 Child process ( $ */