2

Just as the title says, Google gives me nothing and I can't test it on this server.

The command as is follows:

tail -f <file> | fgrep --line-buffered "string" | sed -u 's/stuff//g' >> output.log

Do I need to use kill -SIGTERM <PID> or kill -SIGKILL <PID> to stop a tail -f?

2 Answers 2

1
  • SIGTERM sends a signal to the command and will tell the command to stop itself. If there is a need to clean-up files due to the kill the command can do that.
  • SIGKILL sends a signal to the init system. The command itself does not get even told it is going to get killed.

So you can use both; but SIGTERM should be preferred (it is more graceful).

Will “kill -SIGTERM” stop “tail -f”?

Yes, it will. On Linux tail acts on SIGTERM.

3
  • Roboman1723: This's a wrong answer. @Rinzwind: Why do you say SIGKILL send a signal to the init system?
    – cuonglm
    Dec 18, 2014 at 17:00
  • Will SIGTERM stop tail -f is all I really care about for now. If it does then I'm okay. Dec 18, 2014 at 17:18
  • @cuonglm well it got me a hat :D
    – Rinzwind
    Dec 18, 2014 at 17:20
1

You don't even have to use SIGTERM. tail listens for SIGINT and SIGQUIT too. I'm not sure if there's any difference between signals (it's all specific to tail) but any of these would be better than SIGKILL.

It's quite easy to test too:

$ tail -f /dev/null > /dev/null &
[1] 26599
$ kill -SIGINT $!
[1]+  Interrupt               tail -f /dev/null > /dev/null
2
  • Thanks! I'm essentially trying to emulate a service with this script so at midnight i stop and restart it. I wouldn't want a bunch of interrupted processes hanging around. Good to know though. Dec 18, 2014 at 17:16
  • INT and QUIT: keystrokes are different (control c and control ) and QUIT created a core dump. That's all.
    – Rinzwind
    Dec 18, 2014 at 17:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .