Support

If you have a problem or need to report a bug please email : support@dsprobotics.com

There are 3 sections to this support area:

DOWNLOADS: access to product manuals, support files and drivers

HELP & INFORMATION: tutorials and example files for learning or finding pre-made modules for your projects

USER FORUMS: meet with other users and exchange ideas, you can also get help and assistance here

NEW REGISTRATIONS - please contact us if you wish to register on the forum

Users are reminded of the forum rules they sign up to which prohibits any activity that violates any laws including posting material covered by copyright

A one instance

For general discussion related FlowStone

A one instance

Postby Shoo » Mon Jul 16, 2012 4:15 am

How to allow to run only one instance of a program?

Thanks.
Shoo
 
Posts: 33
Joined: Fri Sep 02, 2011 8:37 am
Location: Russia

Re: A one instance

Postby Embedded » Mon Jul 16, 2012 12:04 pm

One way would be to use the Ruby Module, and write some Ruby code to see if there is already an instance running.

Looking at some web posts it seems people open a file and lock it, if the file is already open then don't allow the 2nd instance (ie. close it straight away).

Here some Ruby Code I found that could be tweaked to do this I think:

Code: Select all
def log(msg)
  output 0, "#{$$} #{msg}"
end

def lock
File.open("test.loc", File::RDWR|File::CREAT, 0644) {|f|
    log "Attempting to lock..."
    if (f.flock(File::LOCK_EX | File::LOCK_NB) == false)
      log "Another instance is already running! Exiting"
      abort
    end
    log "Lock acquired"
    f.rewind
    f.write($$)
    f.flush
    10.times do |i|
      log "Doing work... #{i}"
      sleep(1)
    end
    log "Exiting"
    sleep(1)
  }
end

def event i,v,t
lock

end
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

Re: A one instance

Postby Shoo » Tue Jul 17, 2012 8:38 am

Oh!.. I have a FlowStone 1.1.2((((
Can in it establish some flag to see that one instance is already running?
Shoo
 
Posts: 33
Joined: Fri Sep 02, 2011 8:37 am
Location: Russia

Re: A one instance

Postby Embedded » Tue Jul 17, 2012 10:01 am

You could write a text file to disk, if it exists then close the second instance. But you will have to manage your program exit to delete the file before exiting (so disable close on ESC and make your own close button using the EXE Quit module).

Also if for some reason your app. crashes and doesn't close formally the text file will still be there and then block you starting instance one!

So then you might consider writing a time stamp to the file on a regular basis like a watchdog, so if your app. bombs and you restart the time stamp is old and it allow your to start.

My advice is to Get FlowStone V2 and do it properly using Ruby!
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

Re: A one instance

Postby Shoo » Tue Jul 17, 2012 12:47 pm

Embedded wrote:My advice is to Get FlowStone V2

This decide my boss...

Embedded wrote:So then you might consider writing a time stamp to the file on a regular basis like a watchdog, so if your app. bombs and you restart the time stamp is old and it allow your to start.


It's a great idea!
Thank you very much!
Shoo
 
Posts: 33
Joined: Fri Sep 02, 2011 8:37 am
Location: Russia

Re: A one instance

Postby Shoo » Tue Jul 17, 2012 5:42 pm

Embedded wrote:you will have to manage your program exit to delete the file before exiting (so disable close on ESC and make your own close button using the EXE Quit module).


How hide (or disable) this elements (and the <Alt-F4>) ?
Attachments
quits.jpg
quits.jpg (21.29 KiB) Viewed 26194 times
Shoo
 
Posts: 33
Joined: Fri Sep 02, 2011 8:37 am
Location: Russia

Re: A one instance

Postby Embedded » Tue Jul 17, 2012 11:31 pm

The only way is to use the fullscreen mode.

Hence why it's better to do this the Ruby way.
Embedded
 
Posts: 143
Joined: Sat Oct 30, 2010 1:42 pm

Re: A one instance

Postby Shoo » Wed Jul 18, 2012 4:43 am

Is it possible to use as the flag a presence of signal on some port or device busy?
Shoo
 
Posts: 33
Joined: Fri Sep 02, 2011 8:37 am
Location: Russia

Re: A one instance

Postby DSP » Wed Jul 18, 2012 12:32 pm

Another idea would be to setup inter application communication using UDP and the network modules.

So if you set up a network Server on a port (say 80) in your FlowStone application to listen for a second instance, when a second instance was started (Client) it would send out a message get a response then shut down.
DSP
 
Posts: 150
Joined: Fri May 14, 2010 10:55 pm

Re: A one instance

Postby Morph » Wed Jul 18, 2012 12:39 pm

Embedded wrote:You could write a text file to disk, if it exists then close the second instance. But you will have to manage your program exit to delete the file before exiting (so disable close on ESC and make your own close button using the EXE Quit module).

Also if for some reason your app. crashes and doesn't close formally the text file will still be there and then block you starting instance one!

So then you might consider writing a time stamp to the file on a regular basis like a watchdog, so if your app. bombs and you restart the time stamp is old and it allow your to start.

The TaskList command can make a list of instances of a given program. Then compare if the lines of text exceeds more than that of one program then kill the process. I can build example if needed.
Morph
 
Posts: 53
Joined: Tue Jul 13, 2010 1:59 pm

Next

Return to General

Who is online

Users browsing this forum: No registered users and 71 guests