Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a function which returns the number of running instances #89

Open
ouuan opened this issue Jan 29, 2020 · 4 comments
Open

Add a function which returns the number of running instances #89

ouuan opened this issue Jan 29, 2020 · 4 comments

Comments

@ouuan
Copy link

ouuan commented Jan 29, 2020

Feature request: Add a function which returns the number of running instances. (In fact, I only want to know if one instance is the only running instance.)

This is helpful if you want to behave differently on different number of instances.

My actual need is described in cpeditor/cpeditor#131, if you are interested in where this feature is useful.

@ouuan
Copy link
Author

ouuan commented Jan 29, 2020

Just read the source codes, it seems that what I need is inst->primary + inst->secondary.

UPD: No, inst->secondary is not reduced when a secondary instance closes.

ouuan added a commit to ouuan/SingleApplication that referenced this issue Jan 29, 2020
This function returns the number of running instances, by add a new variable in InstancesInfo.

This feature is asked in itay-grudev#89.
ouuan added a commit to ouuan/SingleApplication that referenced this issue Jan 29, 2020
This function returns the number of running instances, by adding a new variable in InstancesInfo.

This closes itay-grudev#89.
@itay-grudev
Copy link
Owner

Yhea. inst->secondary is used just to generate a unique identifier. It can't be used for counting,=.

ouuan added a commit to ouuan/SingleApplication that referenced this issue Feb 1, 2020
The function: bool SingleApplication::isSingleInstance()
Returns if the instance is the only running instance.

It was hard to check the number of running instances after a crash,
so this is an alternative solution for itay-grudev#89.

It uses a trick: the shared memory will be released after the last
instance detaches from it.
ouuan added a commit to ouuan/SingleApplication that referenced this issue Feb 1, 2020
The function: bool SingleApplication::isSingleInstance()
Returns if the instance is the only running instance.

It is hard to check the number of running instances after a crash,
so this is an alternative solution for itay-grudev#89.

It uses a trick: the shared memory will be released after the last
instance detaches from it.
@ouuan
Copy link
Author

ouuan commented Feb 5, 2020

Here's a solution:

#91 (comment)

But I'm not familiar with it, I hope someone else could implement it, thanks in advance!

@itay-grudev
Copy link
Owner

@ouuan I really appreciate your effort. When I have some more free time I will consider implementing it, but it may be a while as my schedule is really packed right now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants