Question: I wrote the following script which enables timeout of 20 seconds if grep can not find the relevant string in the file.

The script works well, but the output from the script is like this:

```
./test: line 11: 30039: Killed

```

1. how to disable this message from the kill command?
2. how to tell kill command to ignore if process not exist?

THX  

Yael

```
#!/bin/ksh  
( sleep 20 ; [[ ! -z ` ps -ef | grep "qsRw -m1" | awk '{print $2}' ` ]] && kill -9  2>/dev/null ` ps -ef | grep "qsRw -m1" | awk '{print $2}' `   ; sleep 1 ) &
RESULT=$! 
print "the proccess:"$RESULT
grep -qsRw -m1 "monitohhhhhhhr" /var
if [[ $? -ne 0 ]]
then
print "kill "$RESULT
  kill -9 $RESULT
fi
print "ENDED"

./test

the proccess:30038
./test: line 11: 30039: Killed
kill 3003

```

Answer: 
`kill -9 $RESULT &> /dev/null`

This will send `stdout` and `stderr` to /dev/null.
Programming in C:

```
/* Kill process without printing 'Killed' or 'Terminated' message. */
kill(pid, SIGINT);

```

or

```
execl("/bin/bash", "bash", "-c", "kill -SIGINT `pidof <your command>` >/dev/null 2>&1", (char *)NULL);

```

killpid.c

```
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <signal.h>
#include <unistd.h>
/*
    $ gcc -W -Wall -O3 -std=c99 -pedantic -o killpid killpid.c
*/
#define LEN     10

int main()
{
    char line[LEN] = {0};
    FILE *cmd = popen("pidof <your command>", "r");

    fgets(line, LEN, cmd);
    pid_t pid = strtoul(line, NULL, 10);
    printf("pid: %ld\n", pid);

    /* Kill process without printing 'Killed' or 'Terminated' message.*/
    kill(pid, SIGINT);
    pclose(cmd);

    return 0;
}

```

By kill command:

```
$ kill -SIGINT `ps -ef | grep <your command> | awk '{print $2}'` >/dev/null 2>&1

```

or

```
$ kill -SIGINT `pidof <your command>`

```