why no macos programming section?

This is a discussion on why no macos programming section? within the A Brief History of Cprogramming.com forums, part of the Community Boards category; while we have windows and linux programming sections, then why there is no section for mac? i also see that, ...

  1. #1
    Banned
    Join Date
    Nov 2007
    Posts
    678

    why no macos programming section?

    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)?

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    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
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    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.

  4. #4
    Banned
    Join Date
    Nov 2007
    Posts
    678
    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.

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    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.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  8. #8
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    Quote Originally Posted by CornedBee View Post
    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.

  9. #9
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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.)
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    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.
    My Website

    "Circular logic is good because it is."

  12. #12
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    Quote Originally Posted by CornedBee View Post
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by Elysia View Post
    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.
    Last edited by abachler; 04-15-2008 at 08:41 AM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,667
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #15
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    How many tabs do you have open? Ive had a dozen or so open before and never noticed any impact on performance.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Maths For Game Programming?
    By kolliash in forum Game Programming
    Replies: 13
    Last Post: 09-18-2008, 11:53 AM
  2. Help with mprotect and writing on code section
    By raghu2383 in forum Linux Programming
    Replies: 3
    Last Post: 06-20-2008, 02:40 AM
  3. In need of guidance
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2006, 01:43 PM
  4. Section Finder
    By Soul.India in forum C Programming
    Replies: 6
    Last Post: 11-23-2003, 12:43 PM
  5. installing libraries under MacOS, CodeWarrior 4.1
    By Captain Penguin in forum C++ Programming
    Replies: 1
    Last Post: 11-16-2002, 10:28 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21