Sponsored Content
Top Forums Programming Getting another process' environment Post 302177551 by DreamWarrior on Friday 21st of March 2008 12:40:18 PM
Old 03-21-2008
Getting another process' environment

Suppose that I have an environment variable (call it "EVAR") that I set before running a process (call it "myproc"). "myproc" is run multiple times by multiple users and each may set "EVAR" differently. I.E.:

UserA:
export EVAR=v1
myproc

UserB:
export EVAR=v2
myproc

Now "myproc" is running twice, each with different values of "EVAR". Now, let us say that I have another application, "qryproc" who can find all instances of "myproc" that are running. However, for "qryproc" to do its job, it needs to know what "EVAR" looks like for each instance of "myproc" it knows about.

Is this doable? Assume that "qryproc" will be running as root.

Thanks for any ideas....
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Reset environment - ".. /etc/.environment dev_env"

I have been resently working on some ksh script. One of the line in the file writes: .. /etc/.environment dev_env I can not understand what this mean, all I know is .environment is unix system environment file. Is ".." a command? If some one can give me some clue where can I find information... (7 Replies)
Discussion started by: zzwu3591
7 Replies

2. AIX

3004-505 Cannot set process environment

Guys I have an AIX 5.3 box.I am getting following messages if i try to switch to any non root user. bash-3.00# su - sys 3004-505 Cannot set process environment. bash-3.00# su - daemon 3004-505 Cannot set process environment. bash-3.00# su - adm 3004-505 Cannot set process environment.... (4 Replies)
Discussion started by: ak835
4 Replies

3. Shell Programming and Scripting

script to monitor process running on server and posting a mail if any process is dead

Hello all, I would be happy if any one could help me with a shell script that would determine all the processes running on a Unix server and post a mail if any of the process is not running or aborted. Thanks in advance Regards, pradeep kulkarni. :mad: (13 Replies)
Discussion started by: pradeepmacha
13 Replies

4. HP-UX

How can I get environment of running process?!!

In Solaris, here is the command that use to get the environments of running process. pargs -e For example: /export/home/admin> pargs -e 6682 6682: /storage1/opt/wls103/jdk160_05/bin/java -client -Xms256m -Xmx512m -XX:CompileTh envp: XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt envp:... (1 Reply)
Discussion started by: obbzung
1 Replies

5. Shell Programming and Scripting

Shell Script to Kill Process(number of process) Unix/Solaris

Hi Experts, we do have a shell script for Unix Solaris, which will kill all the process manullay, it used to work in my previous env, but now it is throwing this error.. could some one please help me to resolve it This is how we execute the script (and this is the requirement) ... (2 Replies)
Discussion started by: jonnyvic
2 Replies

6. Shell Programming and Scripting

script to monitor the process system when a process from user takes longer than 15 min run.

get email notification from from system when a process from XXXX user takes longer than 15 min run.Let me know the time estimation for the same. hi ,any one please tell me , how to write a script to get email notification from system when a process from as mentioned above a xxxx user takes... (1 Reply)
Discussion started by: kirankrishna3
1 Replies

7. BSD

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (0 Replies)
Discussion started by: naveeng
0 Replies

8. UNIX for Advanced & Expert Users

Process remians in Running state causing other similar process to sleep and results to system hang

Hi Experts, I am facing one problem here which is one process always stuck in running state which causes the other similar process to sleep state . This causes my system in hanged state. On doing cat /proc/<pid>wchan showing the "__init_begin" in the output. Can you please help me here... (6 Replies)
Discussion started by: naveeng
6 Replies

9. Shell Programming and Scripting

Monitoring processes in parallel and process log file after process exits

I am writing a script to kick off a process to gather logs on multiple nodes in parallel using "&". These processes create individual log files. Which I would like to filter and convert in CSV format after they are complete. I am facing following issues: 1. Monitor all Processes parallelly.... (5 Replies)
Discussion started by: shunya
5 Replies

10. Shell Programming and Scripting

Command to get exact tomcat process I am running ignoring other java process

Team, I have multiple batchjobs running in VM, if I do ps -ef |grep java or tomcat I am getting multiple process list. How do I get my exact tomcat process running and that is unique? via shell script? (4 Replies)
Discussion started by: Ghanshyam Ratho
4 Replies
Reliable(3pm)						User Contributed Perl Documentation					     Reliable(3pm)

NAME
Proc::Reliable -- Run external processes reliably with many options. SYNOPSIS
use Proc::Reliable; Create a new process object $myproc = Proc::Reliable->new(); Run a subprocess and collect its output $output = $myproc->run("/bin/ls -l"); Check for problems if($myproc->status()) { print("problem! "); } Run another subprocess, keeping stdout and stderr separated. Also, send the subprocess some data on stdin. $msg = "Hello World "); $p->want_single_list(0); $stdout = $p->run("/usr/bin/fastmail - foo@bar.com", $msg); if($p->status()) { print("problem: ", $p->stderr(), " "); } Another way to get output ($stdout, $stderr, $status, $msg) = $p->run("/bin/ls -l"); OPTIONS
Run Modes $p->run("shell-command-line"); # Launch a shell process $p->run("cmdline", "data"); # Launch a shell process with stdin data $p->run(["cmd", "arg1", ...]); # Bypass shell processing of arguments $p->run(sub { ... }); # Launch a perl subroutine $p->run(&subroutine); # Launch a perl subroutine Option settings below represent defaults $p->num_tries(1); # execute the program only once $p->time_per_try(60); # time per try 60 sec $p->maxtime(60); # set overall timeout $p->time_btw_tries(5); # time between tries 5 sec $p->want_single_list(); # return STDOUT and STDERR together $p->accept_no_error(); # Re-try if any STDERR output $p->pattern_stdout($pat); # require STDOUT to match regex $pat $p->pattern_stderr($pat); # require STDERR to match regex $pat $p->allow_shell(1); # allowed to use shell for operation $p->child_exit_time(1.0); # timeout for child to exit after it closes stdout $p->sigterm_exit_time(0.5); # timeout for child to exit after sigterm $p->sigkill_exit_time(0.5); # timeout for child to exit after sigkill $p->input_chunking(0); # feed stdin data line-by-line to subprocess $p->stdin_error_ok(0); # ok if child exits without reading all stdin $p->stdout_cb(undef); # callback function for line-by-line stdout $p->stderr_cb(undef); # callback function for line-by-line stderr Getting output $out = $p->stdout(); # stdout produced by last run() $err = $p->stderr(); # stderr produced by last run() $stat = $p->status(); # exit code produced by last run() $msg = $p->msg(); # module messages produced by last run() Debug Proc::Reliable::debug($level); # Turn debug on OVERVIEW
Proc::Reliable is a class for simple, reliable and configurable subprocess execution in perl. In particular, it is especially useful for managing the execution of 'problem' programs which are likely to fail, hang, or otherwise behave in an unruly manner. Proc::Reliable includes all the functionality of the backticks operator and system() functions, plus many common uses of fork() and exec(), open2() and open3(). Proc::Reliable incorporates a number of options, including sending data to the subprocess on STDIN, collecting STDOUT and STDERR separately or together, killing hung processes, timouts and automatic retries. DESCRIPTION
A new process object is created by $myproc = Proc::Reliable->new(); The default will run a subprocess only once with a 60-second timeout. Either shell-like command lines or references to perl subroutines can be specified for launching a process in background. A simple list process, for example, can be started via the shell as $out = $myproc->run("ls"); To separate stdout, stderr, and exit status: ($out, $err, $status, $msg) = $myproc->run("ls"); The output data is also stored within the $myproc object for later retrieval. You can also run a perl subroutine in a subprocess, with $myproc->run(sub { return <*>; }); The run Method will try to run the named process. If the process times out (after time_per_try seconds) or has an error defined as unacceptable and you would like to re-run it, you can use the num_tries option. Use the time_btw_tries option to set the number of seconds between runs. This can repeat until maxtime seconds have elapsed. When using num_tries, the user can specify what constitutes an unacceptable error of STDOUT or STDERR output -- i.e. demanding a retry. One common shorthand is to have the run method retry if there is any return from STDERR. $myproc->accept_no_error(); # Re-try if any STDERR $myproc->pattern_stdout($pat); # require STDOUT to match regex $pat $myproc->pattern_stderr($pat); # require STDERR to match regex $pat Subprocess completion is detected when the process closes all filehandles. The process must then exit before child_exit_time expires, or it will be killed. If the subprocess does not exit, it is sent a TERM signal unless sigterm_exit_time is 0. then if it does not exit before sigterm_exit_time expires, it is sent a KILL signal unless sigkill_exit_time is 0. then if it does not exit before sigkill_exit_time expires an error is generated. waiting is done in 0.01 second increments. Proc::Reliable is not MT-Safe due to signals usage. METHODS
The following methods are available: new (Constructor) Create a new instance of this class by writing either $proc = new Proc::Reliable; or $proc = Proc::Reliable->new(); The new method accepts any valid configuration options: $proc = Proc::Reliable->new('maxtime' => 200, 'num_tries' => 3); run Run a new process and collect the standard output and standard error via separate pipes. $out = $proc->run("program-name"); ($out, $err, $status, $msg) = $proc->run("program-name"); by default with a single return value, stdout and stderr are combined to a single stream and returned. with 4 return values, stdout and stderr are separated, and the program exit status is also returned. $msg contains messages from Proc::Reliable when errors occur. Set want_single_list(1) to force stdout and stderr to be combined, and want_single_list(0) to force them separated. The results from run() are stored as member data also: $proc->want_single_list(0); $proc->run("program"); if($proc->status) { print($proc->stderr); exit; } else { print($proc->stdout); } Program exit status is returned in the same format as exec(): bits 0-7 set if program exited from a signal, bits 8-15 are the exit status on a normal program exit. You can also set up callbacks to run a function of your choice as each line of stdout and stderr is produced by the child process using the stdout_cb and stderr_cb options. There are a number of other options. You can also feed the forked program data on stdin via a second argument to run(): $myinput = "hello test "; $output = $proc->run("program-name", $myinput); The first option to run() supports three forms: 1) string containing command string to execute. this incurs shell parsing. 2) arrayref containing split command string to execute. this bypasses shell parsing. 3) coderef to perl function. The first two options are executed via exec(), so the specifics of incurring shell parsing are the same. The second option to run() supports two forms: 1) string containing data to feed on stdin 2) stringref pointing to data to feed on stdin You can start execution of an independent Perl function (like "eval" except with timeout, retries, etc.). Simply provide the function reference like $output = $proc->run(&perl_function); or supply an unnamed subroutine: $output = $proc->run( sub { sleep(1) } ); The run Method returns after the the function finishes, one way or another. debug Switches debug messages on and off -- Proc::Reliable::debug(1) switches them on, Proc::Reliable::debug(0) keeps Proc::Reliable quiet. maxtime Return or set the maximum time in seconds per run method call. Default is 300 seconds (i.e. 5 minutes). num_tries Return or set the maximum number of tries the run method will attempt an operation if there are unallowed errors. Default is 5. time_per_try Return or set the maximum time in seconds for each attempt which run makes of an operation. Multiple tries in case of error can go longer than this. Default is 30 seconds. time_btw_tries Return or set the time in seconds between attempted operations in case of unacceptable error. Default is 5 seconds. child_exit_time When the subprocess closes stdout, it is assumed to have completed normal operation. It is expected to exit within the amount of time specified. If it does not exit, it will be killed (with SIGTERM). This option can be disabled by setting to '0'. Values are in seconds, with a resolution of 0.01. sigterm_exit_time If the time_per_try or max_time has been exceeded, or if child_exit_time action has not succeeded, the subprocess will be killed with SIGTERM. This option specifies the amount of time to allow the process to exit after closing stdout. This option can be disabled by setting to '0'. Values are in seconds, with a resolution of 0.01. sigkill_exit_time Similar to sigterm_exit_time, but a SIGKILL is sent instead of a SIGTERM. When both options are enabled, the SIGTERM is sent first and SIGKILL is then sent after the specified time only if the subprocess is still alive. This option can be disabled by setting to '0'. Values are in seconds, with a resolution of 0.01. input_chunking If data is being written to the subprocess on stdin, this option will cause the module to split() the input data at linefeeds, and only feed the subprocess a line at a time. This option typically would be used when the subprocess is an application with a command prompt and does not work properly when all the data is fed on stdin at once. The module will feed the subprocess one line of data on stdin, and will then wait until some data is produced by the subprocess on stdout or stderr. It will then feed the next line of data on stdin. stdout_cb Set up a callback function to get stdout data from the child line-by-line. The function you supply will be called whenever the child prints a line onto stdout. This is the only way to get output from the child while it is still running, the normal method will give you all the output at once after the child exits. stderr_cb Similar to stdout_cb for stderr data. REQUIREMENTS
I recommend using at least perl 5.003. AUTHORS
Proc::Reliable by Dan Goldwater <dgold at zblob dot com> Based on Proc::Short, written by John Hanju Kim <jhkim@fnal.gov>. Contributions by Stephen Cope and Jason Robertson. COPYRIGHT
Copyright 2001 by Dan Goldwater, all rights reserved. Copyright 1999 by John Hanju Kim, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.10.0 2009-07-10 Reliable(3pm)
All times are GMT -4. The time now is 08:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy