-
Notifications
You must be signed in to change notification settings - Fork 1
Home
- Overview of Process-Monitor
Process-Monitor simplies managing and monitoring processes on Linux systems. It can be very helpful while creating self-healing services .
It can be useful when you want to get the process ids of those processes whose types or names are known.
- Show me some examples:
If you want to find out the process ids of all processes of type “ruby”
require 'process_monitor'
ruby_processes = ProcessMonitor.get_pid("ruby")
If you further want to prune your results you could do so by passing a string which is a part of the process name. So if you have a ruby script and you have set the name to “test_ruby_script” by setting the $0 variable in your script you could easily get the process id by:
test_ruby_script_process_information = ProcessMonitor.get_pid("ruby","test_ruby_script")
The get_pid method returns an array of hashes as follows:
[{:process => {:pid => pid, :command => command_to_launch_process, :status => status_of_process}}, ...]
In order to get individual process details you need to do the following:
test_ruby_script_pid = test_ruby_script_process_information[:process][:pid]
and similarly for command and status of process.
Once you have the pid of a process you can retrieve various details about the process as follows:
# If you want to check if the process exists simply do
is_running = ProcessMonitor.process_is_up?(pid)
___________________________________________________
# Process is running/sleeping/stopped
process_status = ProcessMonitor.get_status(pid)
___________________________________________________
# IO information of the process
io_details = ProcessMonitor.get_io_details(pid)
___________________________________________________
# Stack trace of the process
stack_trace = ProcessMonitor.get_stack_details(pid)
___________________________________________________
# System call made by the process
process_syscall = ProcessMonitor.get_syscall_details(pid)
___________________________________________________
# Resource limitations of the process.
process_limits = ProcessMonitor.get_limits_details(pid)
- Extras
If you want to fetch the first process that matches your criteria do
@first_process = ProcessMonitor.get_first_pid(“ruby”)
This will simply return a hash of the form :
{:process => {:pid => pid, :command => command_to_launch_process, :status => status_of_process}}