Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Is there a file descriptor created for logfile using by logmsg within Perl script

Posted on 2014-01-14
4
Medium Priority
?
198 Views
Last Modified: 2016-06-07
We have a log file which is updated by one Perl script using logmsg.  But I find nothing when I am using lsof|grep logfile to try to find out the process id. Actually I already know which process but I also did not find this logfile descriptor in /proc/processid/fd.  Why?  What is the right way to find out this process ?
0
Comment
Question by:c11v11
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 39781324
How is logmsg defined?
0
 

Author Comment

by:c11v11
ID: 39784438
sub logmsg {
    my ($msg) = @_;

    my $LOG = new IO::File::fcntl("$logFile",'a','lock_ex') or warn "$!";
    my $DateTime = strftime "%b %e %Y %T", localtime;
    if ($LOG) {
        print $LOG "$DateTime,$msg";
        print "$DateTime,$msg" if (! $daemon);
        close $LOG;
    }
}

How can I get the $LOG value? Is this the value for file descriptor?
0
 
LVL 3

Accepted Solution

by:
bigbed earned 160 total points
ID: 40108719
The file is only opened very briefly while writing an individual log message.
The chances of you running lsof at exactly the same time as it's writing a log message are slim.

In the logmsg() function the $LOG variable is scoped so that it's not visible outside that function.
You could either add some code to do what you want to do within the
if ($LOG){} block
or change the scope of $LOG (have a "my $LOG" or "our $LOG" at a higher level in the program and adapt logmsg() to keep the file open and check for the file already being open when it's called).

Here's a rough example
my $LOG;
..
..
sub logmsg {
  my ($msg) = @_;
  $LOG ||= new IO::File::fcntl("$logFile",'a','lock_ex') or warn "$!";
  my $DateTime = strftime "%b %e %Y %T", localtime;
  if ($LOG) {
    print $LOG "$DateTime,$msg";
    print "$DateTime,$msg" if (! $daemon);
  }
}

Open in new window


good luck,
Tim
0
 
LVL 9

Expert Comment

by:Suhas .
ID: 41640814
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: bigbed (http:#a40108719)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

suhasbharadwaj
Experts-Exchange Cleanup Volunteer
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension (http://www.experts-exchange.com/discussions/210281/Attachments-with-no-extension.html). This reminded me of questions tha…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Six Sigma Control Plans

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question