I realize that this might be a stupid issue but I can\'t solve it for hours even if digged stackoverflow site and google throughly.
Here is the base code in .bashrc
using bash (disown
and &>/dev/null
)
you need to run the app in the bg (gkrellm &
) and then disown
it
if ps -C gkrellm -o user | grep "$LOGNAME" &>/dev/null
then echo "gkrellm is already running"
else gkrellm & disown
fi
if you want to be more portable and use posix sh
you will need to use nohup
(part of coreutils
and POSIX)
and also background it (nohup cmd &
)
you'd also use .profile
instead of .bashrc
if ps -C gkrellm -o user | grep "$LOGNAME" 2>/dev/null 1>&2
then echo "gkrellm is already running"
else nohup gkrellm &
fi
other approaches would include - as @Pontus answered - using tools like dtach
, screen
or tmux
, where the command is executed in a detached environment.
by Pontus:
it would make more sense to use your window manager's autostart features
indeed :) as afaik gkrellm
is a GUI app, it's better to autostart it, either using .xinitrc
(if your login manager supports it), or your window manager's autostart facilities.