-1

I have tried to output processes for specific user but with adding some text. I can do like it is described in this answer How to see process created by specific user in Unix/linux but I don't know how to add some words in my output. For example I want to get something like this:

user "some word" PID

When I use ps -ef | grep user I get only user with a lot of options. What am i going to do to get my example user "some word" PID output?

3

Your question is not very clear ... suppose you want to make the list of all processes of the root user, using the command awk we'll print only the column of PID and the arbitrary text:

export USR="root" ;ps  -ef|grep $USR|awk '{ print $1" Some word "$2 }'

you can substitute the value of USR with another user.

0

use

 ps -u user

to select user's process.

to select field

 ps -u archemar -o stime,etime,args
STIME     ELAPSED COMMAND
11:50    03:09:59 sshd: archemar@pts/1
11:50    03:09:59 -bash
14:59       01:04 sshd: archemar@pts/4
14:59       01:04 -bash

see man ps to get the various field.

0
user=root
ps -o user= -o pid= -u "$user" | sed 's/[ 0-9]*$/ "some word"&/'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.