Acces Rights of a backgrounded process - BSD

This is a discussion on Acces Rights of a backgrounded process - BSD ; Hello, I am using a perl script to check for the existence of a process every 5 seconds and under specific circumstances kill the process identified. The script is launched as root and backgrounded from rc.local. It is capable of ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Acces Rights of a backgrounded process

  1. Acces Rights of a backgrounded process

    Hello,

    I am using a perl script to check for the existence of a process every
    5 seconds and under specific circumstances kill the process identified.

    The script is launched as root and backgrounded from rc.local.
    It is capable of performing all actions (e.g. read/write files etc)
    with root privileges except from actually killing another process.

    I believe that I have also ruled out any specific perl related issue by
    implementing a similar shell script. It suffers from the very same
    problem.

    Can anybody suggest what the issue might be?

    I understand that the "mode" of a script running from rc is different
    to one launched from a command line (which incidentally works fine for
    both perl and shell scripts).

    Thanks in advance....

    H.


  2. Re: Acces Rights of a backgrounded process

    According to :
    > Hello,
    >
    > I am using a perl script to check for the existence of a process every
    > 5 seconds and under specific circumstances kill the process identified.
    >
    > The script is launched as root and backgrounded from rc.local.
    > It is capable of performing all actions (e.g. read/write files etc)
    > with root privileges except from actually killing another process.
    >
    > I believe that I have also ruled out any specific perl related issue by
    > implementing a similar shell script. It suffers from the very same
    > problem.
    >
    > Can anybody suggest what the issue might be?


    Well ... with the shell script, I consider it possible that you
    are invoking a program which is not on the very limited PATH which cron
    passes to scripts. The safest work-around is to include the entire path
    to each command in the script -- usually by doing something like:

    KILL=/bin/kill

    and invoking it as

    $KILL

    in the script.

    I'm not sure whether you are invoking anything external from
    your perl script, but if so, it may have similar problem.

    A quick test of the cron on an OBSD 3.4 system shows the value
    of the PATH environment variable to be:

    /bin:/sbin:/usr/bin:/usr/sbin

    so any program which is not to be found along that path will fail to
    execute. Personally, I prefer having *every* program in a script
    executed from the crontab entered as a complete path -- especially ones
    run as root, so there is less chance of executing somebody's program of
    the same name, which may be intended to do things which you would not
    like to have done. :-)

    > I understand that the "mode" of a script running from rc is different
    > to one launched from a command line (which incidentally works fine for
    > both perl and shell scripts).


    The first difference is the PATH environment variable. Start a
    sub-shell, set the path to what cron uses, and see if your script still
    works.

    If it does, then the problem may be instead access to libraries
    which your programs depend upon. Try ldd to see what libraries all of
    the programs need. You may need to set LOAD_LIBRARY_PATH in the script
    to assure that you have everything which you need.

    For that matter -- I'll bet that your perl script depends on a
    bunch of perl functions -- and that is not in the path, either.

    Try to make it work from cron as a shell script first -- once
    that is working, see what you can do to make it work with perl.

    Good Luck,
    DoN.

    --
    Email: | Voice (all times): (703) 938-4564
    (too) near Washington D.C. | http://www.d-and-d.com/dnichols/DoN.html
    --- Black Holes are where God is dividing by zero ---

  3. Re: Acces Rights of a backgrounded process

    Hello,

    Thanks for your efforts, they were atually fruitfull in an unexpected
    way.

    I failed to say before that I did try giving the full path to commands
    I used and there were no errors in the perl script for modules not
    being found.

    However, I did look into the special case when a script/shell is
    launched from the rc scripts and more psecifically how it affects the
    enviroment variables and shell options.

    It turns out that the problem was that the width of terminal set by
    default was so narrow that the fields I was filtering on were not
    there!

    Instead of changing configs for the shell, I simply used a 'ps -axo
    user,pid,command' which allows for all the data to be presented and
    everything worked fine!

    Thanks again for your effort

    H.


  4. Re: Acces Rights of a backgrounded process

    According to :
    > Hello,
    >
    > Thanks for your efforts, they were atually fruitfull in an unexpected
    > way.


    [ ... ]

    > Thanks again for your effort


    I'm glad that you found the solution.

    Enjoy,
    DoN.

    --
    Email: | Voice (all times): (703) 938-4564
    (too) near Washington D.C. | http://www.d-and-d.com/dnichols/DoN.html
    --- Black Holes are where God is dividing by zero ---

+ Reply to Thread