tail
command in current Linux has --pid
option to terminate after certain process id, while tail under MAC OSX doesn't have the same option.
e.g. tail -f --pid=<process_pid>
can terminate tail mode if process_pid terminated.
So how can we get the same result as Linux tail -f --pid
?
Best Answer
There are perhaps several possible ways you can accomplish that.
First solution (easiest): How to replace Mac OS X utilities with GNU core utilities?
Follow the above and install gnu tail. You can then possibly have a function or alias of tail to gtail. like
alias tail=gtail
or even a Bash function:
or just simply call
gtail
altogether instead of BSDtail
Second solution: The second way of doing that would be to make your own function, which you can add in your bash_profile or make a script, whatever suits you. In this script, all that we are doing is just to check if the PID exists or not. If it exists then we tail otherwise we exit with return code 1.
Now, you can call this function like
_tail <file-to-tail> <pid>
, which will do exactly same thing asgtail -f <file-to-tail> --pid=<pid>
However, if you want, you can extend it further and make it same syntaxt as gnu tail by adding another function called
tail
and sourcing it in .bash_profile or in your path as executable.