Re: How do I run only one instance of a program

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 14Sep2008 17:19, Antonio Olivares <olivares14031@xxxxxxxxx> wrote:
| Dear fellow Fedora users,
| 
| I have a little problem when starting KDE.  I have multiple versions of gkrellm running at the same time, and I configured it to "not run multiple instances".  When I run top, I see several gkrellm(s), how do I prevent this?
| 
| I have run this for a while and it is getting tiring
| 
| $ killall -9 gkrellm

Gah! NEVER reach for "-9" first. It is a signal of last resort.

| $ gkrellm &

The trivial way is this:

  pidfile=$HOME/.grkrellm.pid
  if [ -s "$pidfile" ] && pid=$(<"$pidfile") && kill -0 "$pid" 2>/dev/null
  then
    echo GKrellM already running, pid=$pid, not starting a new one.
  else
    gkrellm &           # start gkrellm
    echo $! >"$pidfile" # save the pid
  fi

It is slightly racy, but not on a scale you are likely to encounter in
typical use.

Frankly, "killall" is a command I try NEVER to go near. It is like
trying to break an egg by letting off a grenade.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

Careful and correct use of language is a powerful aid to straight thinking,
for putting into words precisely what we mean necessitates getting our own
minds quite clear on what we mean.      - W.I.B. Beveridge

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux