Created
June 6, 2013 15:39
-
-
Save rlb3/5722501 to your computer and use it in GitHub Desktop.
tail-like
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| my $pid = $ARGV[0]; | |
| my $file = '/tmp/logfile.log'; | |
| open my $fh, '<', $file; | |
| while (pid_exists()){ | |
| while (my $line = readline($fh)) { | |
| print $line; | |
| } | |
| sleep 1; | |
| seek $fh, 0, 1; # this clears the eof flag on $fh | |
| } | |
| sub pid_exists { | |
| return kill 0, $pid; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env perl | |
| use strict; | |
| use warnings; | |
| $|++; | |
| open my $log_fh, '>', '/tmp/logfile.log'; | |
| my $count = 1; | |
| print $$, "\n"; | |
| while (1) { | |
| syswrite $log_fh, $count . "\n"; | |
| $count++; | |
| sleep 2; | |
| } | |
| close $log_fh; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment