Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

restrict pidof to own processes

Tags:

bash

process

pid

In bash,

pidof unison

will list me unison processes of all users. However I am only interested in instances started under my uid.

How can I achieve this?

What I want to do: I'm periodically syncing several accounts on several machines using unison. However, I want the sync to not start, if the current user has manually started unison.

like image 900
Stephan Richter Avatar asked Oct 26 '15 15:10

Stephan Richter


People also ask

What is Pidof process Linux?

pidof command is used to find out the process IDs of a specific running program. It is basically an identification number that is automatically assigned to each process when it is created.

How do I view a specific process at the top?

To filter the top output to a specific process, press the O key and enter the entry as COMMAND=name, where the name refers to the process name. Press ENTER, and the top utility will filter the processes to systemd only. You can also highlight the specific process while keeping other processes in view.


2 Answers

You could use pgrep instead, like

pgrep -u <userid> unison

which will return a list of pids of unison processes that have the euid of the given user.

like image 124
Eric Renouf Avatar answered Sep 30 '22 06:09

Eric Renouf


You can parse ps output like this:

ps -ef | grep unison | grep -v grep | grep "${USER}" | awk '{print $2}'

like image 30
Zloj Avatar answered Sep 30 '22 06:09

Zloj