Only one program instance can be opened through shell.

Source: Internet
Author: User

Using ubuntu10.04 these days, multiple instances of the same program will always be opened, such as Firefox/chromium, and so on, so I wrote the following script to enable the function of only one instance:

#! /Bin/sh
# Name: One
# Auther: maxupeng
# Date: 2011-07-02

If ["$ #"-lt 2]; then
Echo "Usage: One <process name> <program name> [<program parameters>]"
Exit-1
Fi

Process = $1;
Program = $2;
Shift;
Shift;
Params = $ *;

N = 'ps-A | grep $ process | WC-l ';
If ["$ N"-EQ 0]; then
$ Program $ Params;
Fi

The script is named one, run chmod U + x one to add executable permissions, and then put sudo MV one/usr/bin to the bin directory, so that the system can find our script.

Now, change the shortcut command to one chromium-Browse/usr/bin/chromium-browser % u.

Chomium-browse is the name of the chromium process at run time, so that if the chromium process already exists every time you click the chromium shortcut, the new chromium will not be started again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.