Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default pls do reply

    How do i get the process id into a variable ?
    can any one help


    $pid = qx(ps -f|grep srvtst26);
    print "Server Started : $pid \n
    Vema Venkata Guest

  2. Similar Questions and Discussions

    1. reply
      What kind of problems ? Please explain with error messages, etc. Would be nice also to give some details of your system (Operating System) Ray
    2. Why do I get zero sized reply???
      Why after running the following script do I get zero sized reply?? It seems to hang when I access the $link_id (when comparing it, negating,...
    3. do not reply
      Don't tell me what to do! "Dave Slater" <elninia@nospam.adelphia.net> wrote in message news:uIXXa.9708$jg.2578237@news1.news.adelphia.net...
    4. reply for your message
      Hi, In message "your message" on 03/08/26, Mathieu Bouchard <matju@sympatico.ca> writes: |From: matz@ruby-lang.org (Yukihiro Matsumoto)...
    5. jupiters reply
      Your welcome Jim. It is functioning normally. -- Jupiter Jones An easier way to read newsgroup messages:...
  3. #2

    Default Re: pls do reply

    there is a var with it already set:

    perldoc perlvar

    see $PID or $$

    On Tue, Sep 09, 2003 at 10:07:43PM +1000, Vema Venkata wrote:
    > How do i get the process id into a variable ?
    > can any one help
    >
    >
    > $pid = qx(ps -f|grep srvtst26);
    > print "Server Started : $pid \n
    --
    Mat Harrison
    Technical Developer
    3d Computer Systems Ltd.
    [email]matth@3d-computers.co.uk[/email]

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.2 (OpenBSD)

    iD8DBQE/XcQbmbMTrp/jhicRAsyDAJwOBlSQf8fpBTqotiaz+7Aqh/rJRgCfW29T
    DGKtIGhK5TUZSBeRFitTAEg=
    =7srf
    -----END PGP SIGNATURE-----

    Matthew Harrison Guest

  4. #3

    Default Re: process id (pls do reply)

    On Tue, 9 Sep 2003 22:07:43 +1000
    [email]venkatsb@anz.com[/email] (Vema Venkata) wrote:
    > How do i get the process id into a variable ?
    > can any one help
    >
    > $pid = qx(ps -f|grep srvtst26);
    > print "Server Started : $pid \n
    Try giving a description of your problem in the subject line it helps.
    The process id is stored in '$$'. There is no need to jump through hoops
    to get it.

    Cheers,

    GL

    --
    Gavin Laking - Web Development Daemon

    [url]http://www.gavinlaking.co.uk/[/url]
    --
    Gavin Laking Guest

  5. #4

    Default Re: pls do reply

    Vema Venkata wrote:
    >How do i get the process id into a variable ?
    >can any one help
    >
    Process Id of what?
    $$ will contain the process id your current perl script. perldoc perlvar
    If you want to get the process id based on the command name,
    Proc::ProcessTable will interest you.
    >
    >
    >$pid = qx(ps -f|grep srvtst26);
    > print "Server Started : $pid \n
    >
    >
    >
    Sudarshan Raghavan Guest

  6. #5

    Default RE: pls do reply

    #!/proj/ahd02/CAisd/ActivePerl-5.6.0.618/bin/perl
    #/usr/local/bin/perl

    use POSIX qw(strftime);

    $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;

    $xapipgm = "/proj/ahd02/CAisd/site/mods/scripts/srvtst26.pl";

    $pid = qx(pgrep -f srvtst26);

    if ($pid =! 0){
    print "AHD XAPI SERver Running with Process ID '$pid' On $now_string\n" ;
    }
    else{
    $pid = `ps-f|grep $srvtst26`;
    print "Server Started : $pid \n";
    open (F, ">> /proj/ahd02/CAisd/site/mods/scripts/log/init/ahdxapi.init.log") || die "OS Error was $! \n";
    print F "AHDXAPI Server is now started running '$pid' $now_string";
    close F;
    }

    In the above pgm
    $pid = qx(pgrep -f srvtst26); #here it check if the process is running say if it is running it writes to a log file


    else
    $pid = `ps-f|grep $srvtst26`;
    here in the above command it has to grep the process id and return to a variable $pid and write it to a log file





    Vema Venkata Guest

  7. #6

    Default Re: pls do reply

    On Sep 9, Vema Venkata said:
    >How do i get the process id into a variable ?
    >
    >$pid = qx(ps -f|grep srvtst26);
    > print "Server Started : $pid \n
    qx() returns the output. You want to use open():

    $pid = open PS, "ps -f | grep srvtst26 |"
    or die "'ps -f | grep srvtst26' error: $!";

    You can read the output from <PS>.

    --
    Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  8. #7

    Default Re: pls do reply

    Vema Venkata wrote:
    > #!/proj/ahd02/CAisd/ActivePerl-5.6.0.618/bin/perl
    > #/usr/local/bin/perl
    >
    > use POSIX qw(strftime);
    >
    > $now_string = strftime "%a %b %e %H:%M:%S %Y", localtime;
    Huh? What is happening here. Your subject line whines for a response, and yet in your code you totally disregard the
    advice that has been consistently offered. You have launched into executable code without taking the effort to
    use strict;
    use warnings;

    ...and handle your share of the work by dealing with any errors reported.

    Shouldn't you do what you can to help yourself before asking others to help you?


    FWIW, I ran your code, and started dealing with the errors. Then I decided that that was your job.

    Please turn strict and warnings back on, and then ask about anything not clear to you in the error messages.

    Joseph

    R. Joseph Newton Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139