Sponsored Content
Full Discussion: Users and processes
Top Forums UNIX for Dummies Questions & Answers Users and processes Post 302076966 by vgersh99 on Saturday 17th of June 2006 11:49:44 AM
Old 06-17-2006
Assumint this output of 'ps -ef':
Code:
ps -ef:

UID PID PPID C STIME TTY TIME CMD
root 1 0 0 May26 ? 00:00:07 init
root 2 1 0 May26 ? 00:00:00 [keventd]
root 3 1 0 May26 ? 00:00:00 [kapmd]
root 4 1 0 May26 ? 00:00:00 [ksoftirqd_CPU0]
root 5 1 0 May26 ? 00:00:16 [kswapd]
root 6 1 0 May26 ? 00:00:00 [bdflush]
root 7 1 0 May26 ? 00:00:00 [kupdated]

# pipe the output of 'ps -ef' as the input to 'nawk ....' - 'Chiefos.awk' is the 'awk' script.

ps -ef | nawk -f Chiefos.awk

Chiefos.awk:
Code:
BEGIN {
  # save the default awk FieldSeparator by default FS is " " [simplified]
  FSorig=FS
  
  # reset the FieldSeparator to ":" - the field separator of '/etc/passwd'
  FS=":"
  passwd="/etc/passwd"

  # read the content of the '/etc/passwd' into awk associative array
  # indexed by the FIRST field of '/etc/passwd' [UID] with the value
  # of the FIFTH field [full user name]
  while (getline < passwd > 0 )
     arrPWD[$1] = $5

  # reset the FieldSeparator to its original value [" "]
  FS=FSorig
}

# save the the FIRST line of the input [ps -ef] as a 'header'.
FNR==1 { header=$0; next }

# for the 'other' lines build up the array ['arr'] indexed by the FIRST column 
# of the input [UID] with the content of the EVERY record/line of the input
# [ps -ef]. The lines with the same UID [first field - $1] are concatinated with
# 'SUBSEP' in between te strings.
{ arr[$1] = ($1 in arr) ? arr[$1] SUBSEP $0 : $0 }

# After ALL the input lines [from 'ps -ef'] are processed - print out
END {
   # iterate trough the array build based on the input ['ps -ef'] above
   # The iterator [i] is the FIRST field in 'ps -ef'
   for ( i in arr ) {

       # given the iterator [UID] - look it up in the array built based on the 
       # content of '/etc/passwd'.
       # This outputs the UserName and the Header line from 'ps -ef'
       printf("%s\n\t%s\n", arrPWD[i], header)

       # deconstruct the content of the arr[i] - it's a concatination of ALL
       # the lines ['ps -ef'] for a user [current itertator 'i']. The result is an
       # array 'procA' with 'n' entries.
       n=split(arr[i], procA, SUBSEP)

       # iterate through the procA array outputing all cells.
       for(y=1; y <= n ; y++)
          printf("\t%s\n", procA[y])
  }
}


Last edited by vgersh99; 06-17-2006 at 01:52 PM.. Reason: added comments
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Displaying the processes of users

Hi guys, I'm writing a script to display all the current logged on users and the processes they're running, output to a file. The output will look similar to this: User1 (Real name not login name) PID TTY TIME CMD 3179 pts/3 00:00:00 vim User2 PID TTY TIME ... (2 Replies)
Discussion started by: olimiles
2 Replies

2. Shell Programming and Scripting

i need a scipt to email users with idle processes!?

hello, i am VERY new to this whole script world. I need to come up with a script that will email a user if they have an idle process past 500 minutes...any suggestions??? Thanks so much. (0 Replies)
Discussion started by: sheppy28
0 Replies

3. UNIX for Dummies Questions & Answers

users and there processes

I am trying to write a script to list all users and their processes. I cant seem to find out how to link the PID to the user. For example if i run ps -a I get a nice list of all the processes running and their PID, but no information about which user is running them. I need the users real name not... (3 Replies)
Discussion started by: iago
3 Replies

4. Shell Programming and Scripting

Processes and Users

Thx for all the help so far, I really appreciate it, this is the last task I have to do then I am no longer a trainee ^^, which means I can use whatever utility I want. :O I need to write a script that does more or less what is shown below. The Users Name PID TTY TIME CMD 12345 pts/3... (22 Replies)
Discussion started by: barbus
22 Replies

5. UNIX for Advanced & Expert Users

Monitoring Processes - Killing hung processes

Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go? Thank you Richard (4 Replies)
Discussion started by: ukndoit
4 Replies

6. Shell Programming and Scripting

printing each users by processes

hello All, i am trying to get the each users by with thier processing. I have try it in several ways but i am not getting thier my code is #!bin/bash/ users=`cat /etc/passwd | cut -d':' -f5` onlineusers=`users | tr '.' ' '` $onlineusers | while read `$users` do echo `ps -U $users`... (12 Replies)
Discussion started by: sam4now
12 Replies

7. Solaris

Identifying and grouping OS processes and APP processes

Hi Is there an easy way to identify and group currently running processes into OS processes and APP processes. Not all applications are installed as packages. Any free tools or scripts to do this? Many thanks. (2 Replies)
Discussion started by: wilsonee
2 Replies

8. Shell Programming and Scripting

How to display what processes, users have opened at a given time

Hello, What i have to do is make a top 10 list of users sorted by the number of processes opened at a given time. Can anyone help me with finding out for a given moment, for all users how many processes each had opened? (5 Replies)
Discussion started by: gabibyte
5 Replies

9. Shell Programming and Scripting

Sorting the users logged in according to the number of processes

Is it possible to get a list of users sorted by the number of processes executed by each. I have a HP - UX server with 2800 processes running currently. And I want to know the number of processes owned by each person logged in to that server.something like below: user1 : 150 Processes user2 :... (2 Replies)
Discussion started by: engineer
2 Replies

10. Homework & Coursework Questions

Display info about users (UID GID processes terminal)

I would like to get an opinion for my solution for this task and get feedback about better approach or mistakes I have made. 1. The problem statement, all variables and given/known data: The task is to create a script which prints information about users whose names are specified in the... (2 Replies)
Discussion started by: kornfan
2 Replies
RENICE(8)						    BSD System Manager's Manual 						 RENICE(8)

NAME
renice -- alter priority of running processes SYNOPSIS
renice priority [[-p] pid ...] [-g pgrp ...] [-u user ...] renice -n increment [[-p] pid ...] [-g pgrp ...] [-u user ...] DESCRIPTION
renice alters the scheduling priority of one or more running processes. The following who parameters are interpreted as process ID's, process group ID's, or user names. renice'ing a process group causes all processes in the process group to have their scheduling priority altered. renice'ing a user causes all processes owned by the user to have their scheduling priority altered. By default, the processes to be affected are specified by their process ID's. Options supported by renice: -g Force who parameters to be interpreted as process group ID's. -n Instead of changing the specified processes to the given priority, interpret the following argument as an increment to be applied to the current priority of each process. -u Force the who parameters to be interpreted as user names. -p Resets the who interpretation to be (the default) process ID's. For example, renice +1 987 -u daemon root -p 32 would change the priority of process ID's 987 and 32, and all processes owned by users daemon and root. Users other than the super-user may only alter the priority of processes they own, and can only monotonically increase their ``nice value'' within the range 0 to PRIO_MAX (20). (This prevents overriding administrative fiats.) The super-user may alter the priority of any process and set the priority to any value in the range PRIO_MIN (-20) to PRIO_MAX. Useful priorities are: 0, the ``base'' scheduling priority; 20, the affected processes will run only when nothing at the base priority wants to; anything negative, the processes will receive a scheduling preference. FILES
/etc/passwd to map user names to user ID's SEE ALSO
nice(1), getpriority(2), setpriority(2) HISTORY
The renice command appeared in 4.0BSD. BUGS
Non super-users can not increase scheduling priorities of their own processes, even if they were the ones that decreased the priorities in the first place. BSD
June 9, 1993 BSD
All times are GMT -4. The time now is 09:24 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy