Bash 脚本 - 运行应用程序的当前实例或新实例
我在 ubuntu 中添加了应用程序的快捷方式。每次我按下快捷键时,都会创建一个新的应用程序实例。我只需要一个实例,我可以使用什么脚本来打开应用程序的现有实例或在应用程序未运行时创建一个新实例?
I added a shortcut to an application in ubuntu. Each time i press shortcut keys, a new instance of application is created. I need only one instance, what script i can use to open the existing instance of application or creates a new one if the application is not running?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很大程度上取决于应用程序。最简单的情况是已知的进程名称只能由您运行(即系统上没有杂散实例):
打开现有应用程序可能会很棘手,并且再次取决于应用程序。我建议您看一下 alltray 东西,并特别注意
alltray - -help
输出。由 ypnos 编辑:
如果您只想将此限制为当前用户,您应该使用 pgrep 而不是 pidof,如下所示:
It depends greatly on the application. The most trivial case would be the known process name which can only be run by you (that is, no stray instances on the system):
Opening an existing application may get tricky and, again, depends on the application. I'd suggest that you take a look at alltray thingie and pay special attention to the
alltray --help
output.Edit by ypnos:
If you want to restrict this to the current user only, you should use pgrep instead of pidof, like this:
您还可以尝试这样的脚本:
如果您将脚本称为“runner.sh”,则可以像这样使用它:
用于 pidof 不起作用的情况。否则就选择黑客的解决方案,它也更强大。
You can also try a script like this:
If you called the script 'runner.sh', you can use it like this:
Is for cases where pidof doesn't work. Else go for hacker's solution, which is also more robust.