You are not logged in.
Pages: 1
I am wondering if there is a way to get the pid of an executing process, say conky.
I am using conky as an alert box, displaying a certain text, then I kill conky using
killall. I would instead rather use
kill, but without knowing the pid of the alert box, I cannot do much. Perhaps you guy would have any ideas? Thanks!
Last edited by mtello17 (2014-04-19 22:26:05)
Offline
Try this:
ps aux|grep -v awk|awk '/conky/ {print $2}'If you want to use a variable, say PROCESS="conky", try
ps aux|grep -v awk|awk /$PROCESS/ '{print $2}'or
ps aux|grep -v awk|awk "/$PROCESS/" '{print $2}'Offline
Check commands "pidof", "pgrep", and "pkill", too.
Offline
Offline
ps aux|grep -v awk|awk /$PROCESS/ '{print $2}'or
ps aux|grep -v awk|awk "/$PROCESS/" '{print $2}'
You don't need the grep with awk:
ps aux | awk '/tmux/ && !/awk/ {print $2}'Offline
a few options:
pkill conky
pidof conky
ps --format="pid" -C conky
# with short command name:
ps --format="pid,comm" -C conky
# or full command name (includes flags, etc):
ps --format="pid,command" -C conkyLast edited by HiImTye (2014-04-19 09:09:34)
Offline
doesn't conky have a timeout argument or similar?
Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline
$ ps aux|grep conkyIs how I'd get the pid for conky.
Last edited by bergersau (2014-04-19 11:41:34)
Offline
karol's link is answering this question. It's the only one that makes sure to get the right PID in case you got multiple conky's.
Personal website: reboot.li
GitHub: github.com/rebootl
Offline
I used top for that task. It lists all active processes along with their PID, user, RAM usage and CPU usage.
Offline
How is manually parsing `ps` output better than `killall /usr/bin/conky` ?
Offline
I'm using fluxbox to create keymodes (like vim). Bringing up an alert box through conky tells me that I am in a certain keymode, and when I leave my keymode I kill my alert box (conky).
Knowing the pid of an instance of conky that I just ran is paramount, otherwise any other conky instance could also be killed.
Last edited by mtello17 (2014-04-19 21:13:31)
Offline
See I don't want to get the pid of a process running in the background, I instead want to get the pid of a conky instance when I run it.
Last edited by mtello17 (2014-04-19 21:13:09)
Offline
Karol's answer, which would be perfect for most people, doesn't work with multiple instances of bash, and what I need is something that would work on multiple instances of bash
Here is what I'm doing:
# current window commands
Mod4 w Mod4 w :MacroCmd { Exec conky -t "Window Mode" -a top_right -y 0 -b & KEYMODE=$! } { KeyMode WindowMode None }
WindowMode: None Escape :MacroCmd {Exec kill $KEYMODE} { KeyMode default }Last edited by mtello17 (2014-04-19 21:59:31)
Offline
Solved it with the help of karol's answer. I just created this simple script:
#!/bin/env bash
_1=$1
_2=$2
if "$_2" == ""; then
cr=kill_default
else
cr=$_2
fi
echo "kill $_1" >> ~/bin/$cr
chmod 777 ~/bin/$crLast edited by mtello17 (2014-04-20 02:40:12)
Offline
if you want to get it from another script, have your first script echo your pid to /tmp/ such as
conky
echo $! > /tmp/myPIDthen just get it in your other script
Offline
$XDG_RUNTIME_DIR would be more appropriate for PID files than /tmp.
Offline
Cool, that also works, and is probably less work, thanks
Offline
Pages: 1