PDA

View Full Version : why no macos programming section?



manav
04-14-2008, 01:42 AM
while we have windows and linux programming sections, then why there is no section for mac?

i also see that, there are not any mac related questions either.

anyway my question is:
how to detect if a program is already running (using C/C++ and on mac, of course)?

matsp
04-14-2008, 02:02 AM
Same answer as for any other "detect if my program is running" - you can use:
* some form of system information (which is tricky, since it's likely to not work if the "other" user of the same application is logged in under a different account and you haven't got root privileges).
* Use a unique file that is opened with exclusive rights, so that if any other instance tries to open this file, it's not able to. The benefit of this method is, as you probably realize, that it's available on just about all platforms that support files - only ones where you can't have exclusive access to a file are unable to use this method.
* Use some sort of global named semaphore (or other system resource that is global and named) - this works along the same lines as the file method above, but without using the filesystem as such.

Finally, What is the actual problem you are trying to solve - there may be other better solutions if we understand what you are trying to solve [detecting other instances of the same application is only really useful if there is a license condition that you can only have one app per machine - most other cases are false needs of detecting the application, and just trying to avoid shared resource problems that should be solved by exclusive access detection on the resource itself].

--
Mats

master5001
04-14-2008, 02:50 AM
On a quick note about the "Why no MacOS board?" I believe you already answered your question by noting the lack of Mac specific questions. Though, and I say this with limited Mac programming experience, its more or less the same thing as writing a program for Linux. Which comes as no shock since its based on Unix. In other words, there seems to be a total lack of Mac newbies here and/or if there are they are satisfied by the boards dedicated to similar operating systems.

To change this fact is a simple matter of forcing everyone you know to buy a Mac (I recommend an UZI or similar type of automatic pistol) then make all those people desire the urge to develop software. But don't give them too much information. Then they couldn't ask simple questions that a quick google search could resolve of the folks here.

manav
04-14-2008, 02:54 AM
thanks Mats for the above suggestions!
on linux what i am doing is:
- read the /proc directory
- read the /proc/<pid>/status file
- match the executable name in the above file to the one i want to check for

i was assuming that the same method should work on macos as well. but it seems that it does not work on mac.

for the given project specifications i need to implement this feature, that, i must check before continuing, that, the program is not already running.

PS: on windows i use winapi snap shot function and then perform the check.

abachler
04-14-2008, 08:40 AM
With windows its as simple as trying to create a mutex, if the mutex exists, the program is already running. takes all of 2 lines of code. Come on over to the dark side, you don't realize the POWER of the Win32 API, muahahahaha.

brewbuck
04-14-2008, 09:59 AM
You could search the process list for a process with the right name. But it could be another program that happens to have the same name. Or the original program could have changed its name so that you would not find it in the process list.

You could look for a resource that the process uses, like an open socket, or a window in the GUI. But again, you can't prove that the owner of that resource is actually the program you are looking for.

You could look for a PID file or some other indication the program deliberately leaves that it is running. But that's not reliable either, because the program could be buggy, or it could have crashed and not gotten the chance to erase the "I'm running" data, or some other program could have destroyed the information you are looking for.

Basically, there is no way to prove beyond doubt that a program is already running, although sometimes you can prove that it isn't.

CornedBee
04-14-2008, 10:11 AM
And even if you can prove it, that information is worthless, since any check that a program is running is subject to a race condition - the moment you've detected the running program, it might terminate, leaving you with incorrect information.

That said, I disagree that detecting a previous instance is useless. Many large applications (e.g. Firefox) do it and react by instructing the running instance to create a new window.

brewbuck
04-14-2008, 10:26 AM
That said, I disagree that detecting a previous instance is useless. Many large applications (e.g. Firefox) do it and react by instructing the running instance to create a new window.

It's definitely not useless, just unreliable. I wouldn't use any of these tricks to make a decision to do something irreversible or destructive, for instance.

Elysia
04-14-2008, 10:39 AM
Also, for most of the times, don't stop the user from running multiple instances.
Unless it's absolutely, absolutely, absolutely critical, then don't do it. Try to make the program work fine with multiple instances or, let it run with a few compability problems. It's much better than hindering multiple instances. Let the end user decide.
I'm already annoyed as it is that you can't run multiple firefox instances.

CornedBee
04-14-2008, 03:06 PM
I'm already annoyed as it is that you can't run multiple firefox instances.
Really? What degradation of functionality have you experienced that make you feel that way?

(On a side note, Firefox allows you to run multiple instances, as long as they use different profiles.)

DavidP
04-14-2008, 06:23 PM
Mac OS X is a Unix operating system, therefore for the most part it falls right into the same category as Linux/Unix.

In terms of GUI stuff and specific Mac OS X APIs (Cocoa, Carbon, etc.), most of that stuff is done with Objective-C. Since we don't have an Objective-C board....those things don't get talked about a lot.

Elysia
04-15-2008, 01:38 AM
Really? What degradation of functionality have you experienced that make you feel that way?

(On a side note, Firefox allows you to run multiple instances, as long as they use different profiles.)

Because one window affects the other. If one window is slow, everything is slow. This could be solved with another instance.
And a different profile just defeats the whole purpose since everything is tied to this profile I don't surf with multiple ones.

abachler
04-15-2008, 08:31 AM
I'm already annoyed as it is that you can't run multiple firefox instances.

Wha exactly do you nee to do with multiple instances that tabs wont accomplish? Honestly, tabs where put in to alleviate the need for multiple instances. This feature is so popular that even MS adopted it. If the window is slow because of bandwidth, mutliple instances wont help this. If it is slow because of doing some java/activeX/etc. then multiple instances wont help this either, since firefox runs each tab in a seperate thread IIRC. Maybe you just think it is helping because foreground windows get a priority boost.

Elysia
04-15-2008, 08:45 AM
Tabs slow down the application if there's too many. It's not a bandwidth problem.
And IIRC, I've never seen Firefox eat more than 50&#37; CPU.

abachler
04-15-2008, 09:11 AM
How many tabs do you have open? Ive had a dozen or so open before and never noticed any impact on performance.

Elysia
04-15-2008, 09:15 AM
I used to have like 30-40.
Plus opening onening many tabs at once will block the browser entirely until those tabs finish loading.
It may related to extensions, but then again, if I could just run another instance, those problems would be solved!

brewbuck
04-15-2008, 09:35 AM
I used to have like 30-40.
Plus opening onening many tabs at once will block the browser entirely until those tabs finish loading.
It may related to extensions, but then again, if I could just run another instance, those problems would be solved!

I think a preferable solution, in lieu of allowing multiple instances of Firefox, is to fix all the damn bugs in Firefox so it works how it's supposed to.

(Hey, I use Firefox, that's why I complain.)

Elysia
04-15-2008, 09:37 AM
Good luck with that. The extensions are proving pretty problematic. And I don't know if they're going to address it anytime soon.

idelovski
04-15-2008, 02:03 PM
I don't use FireFox.

I have it, but I don't use it because its controls look strange on Mac. And I don't use it on
Windows because of some other reasons I'm sure everybody here would like to hear but I
don't feel like hijacking this thread about Mac programming. ;)

Anyway, all relevant Mac programming talk is going on at Apple sponsored official mailing lists.
I hate mailing lists, but that is almost all Mac folks have right now.

A year ago I asked the same question about the Mac forum at c-board without any success.
(You can't find that thread because it got erased at one of those site crashes). On the other
hand, half of the Mac programming questions are unix questions and the other half - well,
that half should be further halved into C/Carbon & ObjC/Cocoa and after all that you're left
with a very small piece of pie.

In other words, there are more Mac programmers here than we think, but even that seems
to be 'not enough!'

Mario F.
04-15-2008, 02:23 PM
In other words, there are more Mac programmers here than we think, but even that seems to be 'not enough!'

Nope. And with reason, I would risk.
What would be enough was enough questions on mac related programming. Until then, I'm afraid it makes sense not having a mac specific board or an Objective C board.