OESF | ELSI | pdaXrom | OpenZaurus | Zaurus Themes | Community Links | Ibiblio

IPB

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Run Only One Copy Of Program?
desertrat
post Mar 24 2006, 12:41 AM
Post #1





Group: Members
Posts: 742
Joined: 15-October 05
From: Gulag, Siberia
Member No.: 8,322



Having mapped some often used programs onto the application keys the problem is that whenever the application key is pressed it just keeps starting a new copy of the mapped program.

What I would is that when an application key is pressed:

1) if mapped program is not running, start it
2) if already running bring it to front

Is this possible?

-- cheers
Go to the top of the page
 
+Quote Post
gromituk
post Mar 24 2006, 02:16 AM
Post #2





Group: Members
Posts: 207
Joined: 22-June 04
Member No.: 3,783



I suppose you could map the key to a shell script which does a "ps -A|grep <name>" to see if a copy of the application is already running, and start it if not. Don't know how to bring it to the front though, but having the PID could be useful here! More rigorous would be for it to get the PID of the app when it starts it up and store it in a file somewhere.
Go to the top of the page
 
+Quote Post
desertrat
post Mar 24 2006, 03:03 AM
Post #3





Group: Members
Posts: 742
Joined: 15-October 05
From: Gulag, Siberia
Member No.: 8,322



QUOTE(gromituk @ Mar 24 2006, 10:16 AM)
I suppose you could map the key to a shell script which does a "ps -A|grep <name>" to see if a copy of the application is already running, and start it if not.  Don't know how to bring it to the front though, but having the PID could be useful here!  More rigorous would be for it to get the PID of the app when it starts it up and store it in a file somewhere.


That was exactly what I had been thinking, and like you I don't know how to bring an app to front either smile.gif

But I was hoping there was a more elegant solution (ie one that doesn't require so much hard work). The WMs certainly knows what apps are running and are able to "bring it to front", for instance when you Alt-TAB to cycle through windows. If I can hook into that mechanism then I'll be all set. Any ideas?

-- cheers
Go to the top of the page
 
+Quote Post
pungipungi
post Mar 25 2006, 11:16 AM
Post #4





Group: Members
Posts: 74
Joined: 11-March 05
From: Austria
Member No.: 6,614



On the agenda vr3 there was a utility called runone which does some parts of the job
(I think it uses a more stable mechanism via proc files and temp files to check if a program is already runing).
The source can be found on
http://agenda-snow.sourceforge.net/release/source/libs/

Maybe that's a possible base for a start ....
sad.gif but that's not the easy way

Andreas
Go to the top of the page
 
+Quote Post
grog
post Mar 25 2006, 11:49 AM
Post #5





Group: Members
Posts: 692
Joined: 27-January 04
From: Canada
Member No.: 1,564



The 'Standard UNX Way' is for the program to save it's PID into a file under /var/run & remove it when it closes. When the program starts up, it first checks to see if the pidfile exits, and if so then uses the PID in the file to check for an active process. If one exists, then it exits.

Here's a simple bit of code that I use at the top of all of my scripts that I need to only have one instance. It of course has to be run as root, or you could change the permissions of the /var/run directory. All you'd have to do is to write it as a wrapper script for binary programs. The exec command is used to run a binay in the same process (i.e. with the original PID). Otherwise just include the rest of the script right after the echo. The script will clean iself up when it closes because of the trap.

HTH

CODE
#!/bin/sh

PIDFILE=/var/run/${0##*/}.pid

if [ -s $PIDFILE ]; then
   ps -ax | grep "^ *$(cat $PIDFILE).*${0##*/}" >/dev/null 2>&1 && exit
fi

trap "\rm -f $PIDFILE" 0 1 2 3 15
echo $$ >| $PIDFILE

exec myprog
Go to the top of the page
 
+Quote Post
Armagon
post Mar 25 2006, 09:24 PM
Post #6





Group: Members
Posts: 106
Joined: 19-October 05
From: Cardston, AB, Canada
Member No.: 8,348



QUOTE(desertrat @ Mar 24 2006, 03:03 AM)
QUOTE(gromituk @ Mar 24 2006, 10:16 AM)
I suppose you could map the key to a shell script which does a "ps -A|grep <name>" to see if a copy of the application is already running, and start it if not.  Don't know how to bring it to the front though, but having the PID could be useful here!  More rigorous would be for it to get the PID of the app when it starts it up and store it in a file somewhere.


That was exactly what I had been thinking, and like you I don't know how to bring an app to front either smile.gif

But I was hoping there was a more elegant solution (ie one that doesn't require so much hard work). The WMs certainly knows what apps are running and are able to "bring it to front", for instance when you Alt-TAB to cycle through windows. If I can hook into that mechanism then I'll be all set. Any ideas?

-- cheers
*



I was thinking that the Aterm launcher (beside the start menu on the taskbar, in a default install of pdaXrom 1.1.0beta1) seems to be able to keep track of this. It even seems to be able to toggle the window on and off.

The file is /usr/share/applications/mb-launcher-term.desktop, and it contains this noteable line:
CODE
Exec=mb-applet-launcher -o -1 --desktop /usr/share/applications/aterm.desktop


I wonder if you can leverage off of that?

Armagon
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 29th August 2014 - 06:18 AM