Sponsored Content
Top Forums Programming parsing currently running processes Post 302092741 by blowtorch on Thursday 12th of October 2006 03:32:46 AM
Old 10-12-2006
That becomes the same as the second method. Here's what I'm trying to say in pseudocode:
method 1 - read /proc into a list
Code:
while readdir of /proc returns valid entries; do
        read the /proc/<pid>/psinfo file into a struct
        append the struct to a list of such structs
done
for each element in list; do
        for each element in list of structs; do
                compare element against the ps cmd line from struct
                if match, increase count of pattern instances
        done
        if count of pattern instances
                below lower threshold
                        raise alert
                above upper threshold
                        raise alert
                between the correct bounds
                        do nothing
done

method 2 - read /proc for each entry in the list
Code:
for each element in list; do
        while readdir of /proc returns valid entries; do
                read the /proc/<pid>/psinfo file into a struct
                compare element against the ps cmd line from struct
                if match, increase count of pattern instances
        done
        if count of pattern instances 
                below lower threshold
                        raise alerts
                above upper threshold
                        raise alerts
                between the correct bounds
                        do nothing
done

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Running two processes in background

hi there, here's what i need in my korn-shell: ... begin korn-shell script ... nohup process_A.ksh ; nohup process_B.ksh & ... "other stuff" ... end lorn-shell script in plain english i want process A and process B to run in the background so that the script can continue doing... (6 Replies)
Discussion started by: jacob_gs
6 Replies

2. Programming

getting certain info for all processes currently running

i am writing a utility that displays information about all the running processes in the /proc directory. I do not know how to get the following information for each of the processes in the /proc directory: -effective user id -effective user name -effective group id -effective group name... (3 Replies)
Discussion started by: Yifan_Guo
3 Replies

3. Solaris

About running processes in background

Hi, I need to establish a procedure that will start an application in background each time my remote Solaris server is (re)started. This would be a kind of daemon. I am no sysadmin expert, so I am looking for pointers. How should I proceed? What are the main steps? Thanks, JVerstry (9 Replies)
Discussion started by: JVerstry
9 Replies

4. Shell Programming and Scripting

Need help with running processes script

I'm doing a script with the Shell. I need that it only show the number of running processes. Ex: echo "There are `command` running processes" Thnx! Pd: Sorry the idiom. I'm spanish. (2 Replies)
Discussion started by: Ikebana
2 Replies

5. Shell Programming and Scripting

Need help with running processes script

I'm doing a script with the Shell. I need that it only show the number of running processes. Ex: echo "There are `command` running processes" Thnx! Pd: Sorry the idiom. I'm spanish. (5 Replies)
Discussion started by: Ikebana
5 Replies

6. Shell Programming and Scripting

how to know the running processes.

Hi can anybody help me regarding this.. i want know the output of ps -ef with explanation. how can we know the running processess. this is the output of ps -elf F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 19 T root 0 0 0 0 SY ... (1 Reply)
Discussion started by: rajesh_pola
1 Replies

7. Solaris

Running processes on GZ/LZ

Hi guys just a question is it normal to see running process on a non-global zone in the global zone... processes such as cron. (3 Replies)
Discussion started by: batas
3 Replies

8. Linux

Running processes

Hi guys is it normal to have 5-10 cron/syslog processes running... in my case i got 10 cron process running. (4 Replies)
Discussion started by: batas
4 Replies

9. Solaris

Sendmail processes not running

Hi All! I am trying to get sendmail to work but unsuccessfull...when I run ps -ef | grep sendmail root 10578 10561 0 11:01:24 pts/1 0:00 grep sendmail I do not see its processes When I run the following commands: bash-3.00# svcs sendmail svcs: Pattern 'sendmail' doesn't match... (9 Replies)
Discussion started by: fretagi
9 Replies

10. UNIX for Beginners Questions & Answers

Many processes running at the same time

Hello everybody , I launched cron to execute a task every hour but the job takes more than hour that's why I'm getting more than 1000 cron processes running at the same time !!! My question is how to tell cron not to execute unless the job terminated in order to have only one process running .... (14 Replies)
Discussion started by: beautymind
14 Replies
pgrep(1)							   User Commands							  pgrep(1)

NAME
pgrep, pkill - find or signal processes by name and other attributes SYNOPSIS
pgrep [-flvx] [-n | -o] [-d delim] [-P ppidlist] [-g pgrplist] [-s sidlist] [-u euidlist] [-U uidlist] [-G gidlist] [-J projidlist] [-t termlist] [-T taskidlist] [-c ctidlist] [-z zoneidlist] [pattern] pkill [-signal] [-fvx] [-n | -o] [-P ppidlist] [-g pgrplist] [-s sidlist] [-u euidlist] [-U uidlist] [-G gidlist] [-J projidlist] [-t termlist] [-T taskidlist] [-c ctidlist] [-z zoneidlist] [pattern] DESCRIPTION
The pgrep utility examines the active processes on the system and reports the process IDs of the processes whose attributes match the cri- teria specified on the command line. Each process ID is printed as a decimal value and is separated from the next ID by a delimiter string, which defaults to a newline. For each attribute option, the user can specify a set of possible values separated by commas on the command line. For example, pgrep -G other,daemon matches processes whose real group ID is other OR daemon. If multiple criteria options are specified, pgrep matches processes whose attributes match the logical AND of the criteria options. For example, pgrep -G other,daemon -U root,daemon matches processes whose attributes are: (real group ID is other OR daemon) AND (real user ID is root OR daemon) pkill functions identically to pgrep, except that each matching process is signaled as if by kill(1) instead of having its process ID printed. A signal name or number may be specified as the first command line option to pkill. OPTIONS
The following options are supported: -c ctidlist Matches only processes whose process contract ID is in the given list. -d delim Specifies the output delimiter string to be printed between each matching process ID. If no -d option is specified, the default is a newline character. The -d option is only valid when specified as an option to pgrep. -f The regular expression pattern should be matched against the full process argument string (obtained from the pr_psargs field of the /proc/nnnnn/psinfo file). If no -f option is specified, the expression is matched only against the name of the executable file (obtained from the pr_fname field of the /proc/nnnnn/psinfo file). -g pgrplist Matches only processes whose process group ID is in the given list. If group 0 is included in the list, this is inter- preted as the process group ID of the pgrep or pkill process. -G gidlist Matches only processes whose real group ID is in the given list. Each group ID may be specified as either a group name or a numerical group ID. -J projidlist Matches only processes whose project ID is in the given list. Each project ID may be specified as either a project name or a numerical project ID. -l Long output format. Prints the process name along with the process ID of each matching process. The process name is obtained from the pr_psargs or pr_fname field, depending on whether the -f option was specified (see above). The -l option is only valid when specified as an option to pgrep. -n Matches only the newest (most recently created) process that meets all other specified matching criteria. Cannot be used with option -o. -o Matches only the oldest (earliest created) process that meets all other specified matching criteria. Cannot be used with option -n. -P ppidlist Matches only processes whose parent process ID is in the given list. -s sidlist Matches only processes whose process session ID is in in the given list. If ID 0 is included in the list, this is inter- preted as the session ID of the pgrep or pkill process. -t termlist Matches only processes which are associated with a terminal in the given list. Each terminal is specified as the suffix following "/dev/" of the terminal's device path name in /dev. For example, term/a or pts/0. -T taskidlist Matches only processes whose task ID is in the given list. If ID 0 is included in the list, this is interpreted as the task ID of the pgrep or pkill process. -u euidlist Matches only processes whose effective user ID is in the given list. Each user ID may be specified as either a login name or a numerical user ID. -U uidlist Matches only processes whose real user ID is in the given list. Each user ID may be specified as either a login name or a numerical user ID. -v Reverses the sense of the matching. Matches all processes except those which meet the specified matching criteria. -x Considers only processes whose argument string or executable file name exactly matches the specified pattern to be match- ing processes. The pattern match is considered to be exact when all characters in the process argument string or exe- cutable file name match the pattern. -z zoneidlist Matches only processes whose zone ID is in the given list. Each zone ID may be specified as either a zone name or a numer- ical zone ID. This option is only useful when executed in the global zone. If the pkill utility is used to send signals to processes in other zones, the process must have asserted the {PRIV_PROC_ZONE} privilege (see privileges(5)). -signal Specifies the signal to send to each matched process. If no signal is specified, SIGTERM is sent by default. The value of signal can be one of the symbolic names defined in signal.h(3HEAD) without the SIG prefix, or the corresponding signal number as a decimal value. The -signal option is only valid when specified as the first option to pkill. OPERANDS
The following operand is supported: pattern Specifies an Extended Regular Expression (ERE) pattern to match against either the executable file name or full process argument string. See regex(5) for a complete description of the ERE syntax. EXAMPLES
Example 1 Obtaining a Process ID Obtain the process ID of sendmail: example% pgrep -x -u root sendmail 283 Example 2 Terminating a Process Terminate the most recently created xterm: example% pkill -n xterm EXIT STATUS
The following exit values are returned: 0 One or more processes were matched. 1 No processes were matched. 2 Invalid command line options were specified. 3 A fatal error occurred. FILES
/proc/nnnnn/psinfo Process information files ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
kill(1), proc(1), ps(1), truss(1), kill(2), signal.h(3HEAD), proc(4), attributes(5), privileges(5), regex(5), zones(5) NOTES
Both utilities match the ERE pattern argument against either the pr_fname or pr_psargs fields of the /proc/nnnnn/psinfo files. The lengths of these strings are limited according to definitions in <sys/procfs.h>. Patterns which can match strings longer than the current limits may fail to match the intended set of processes. If the pattern argument contains ERE meta-characters which are also shell meta-characters, it may be necessary to enclose the pattern with appropriate shell quotes. Defunct processes are never matched by either pgrep or pkill. The current pgrep or pkill process will never consider itself a potential match. SunOS 5.11 6 May 2004 pgrep(1)
All times are GMT -4. The time now is 08:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy