readey has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks, I am trying to write a pTk interface to ppp in Linux. What I can't seem to fathom is how to detect that pppd is running and for how long and return that information to Perl. Though I suspect the second part will not be too difficult. Any helpful suggestions, meditations? Thankx, readey

Replies are listed 'Best First'.
Re: Getting Linux system info
by pope (Friar) on Jul 03, 2001 at 12:36 UTC
Re: Getting Linux system info
by Zaxo (Archbishop) on Jul 03, 2001 at 12:42 UTC
    my $ppid = `/sbin/pidof pppd`; # cannot be 0 so logic works # $ppid is empty unless pppd is running. # Having the pid lets you signal the daemon

    You can also poke around in /proc for all sorts of interesting system info. All you need to do is treat it as ordinary files and dirs.

    After Compline,
    Zaxo

    Update: my $pstart=`/bin/ps -C pppd -o pid=,start_time=`; will return space delimited pid and start time. The time format shifts from date to time for young processes, so parsing is difficult.

Re: Getting Linux system info
by stefan k (Curate) on Jul 03, 2001 at 12:42 UTC
    This is not particular perl-ish, but I'd do that job with ps anyway...

    Example:

    ps -eo start_time,user,command | grep $USER | grep pppd | grep -v grep + | cut -d' ' -f1
    gives you the start time of the pppd demon. The etime switch to ps gives you the elapsed time, but you need a more tricky cut (maybe perl ? ;-) to get it...

    Regards... Stefan