• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            posts - 319, comments - 22, trackbacks - 0, articles - 11
              C++博客 :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            Find path of an application

            Posted on 2012-04-18 22:44 RTY 閱讀(599) 評(píng)論(0)  編輯 收藏 引用 所屬分類: C/C++Mac os
            Mailing Lists: Apple Mailing Lists
            Image of Mac OS face in stamp
            [Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

            Re: Find path of an application


            • SubjectRe: Find path of an application
            • From: Terry Lambert <email@hidden>
            • Date: Tue, 16 Dec 2008 02:01:54 -0800
            • Delivered-to: email@hidden
            • Delivered-to: email@hidden

            On Dec 16, 2008, at 1:00 AM, Rakesh Singhal wrote:
            I am done with finding the process is running or not. Thanks a lot. Still I am stuck with second issue to find the path to my application in my system. Actually there are 3 steps:

            1. To know that application is running or not?  Now it is done. 2. If not then get the path of application where it was installed (user can change the path during installation). 3. Launch the application.

            My code is standard C++ tool so I want to use only C and C++ APIs. Please suggest me. 

            You said this was a GUI app that you didn't control the sources to. So control it anyway by renaming the binary in the bundle and putting a stub in there that will save off the id for you and then reexec the real binary:


            --- example with no error checking --- #include <mach-o/dyld.h>	/* _NSGetExecutablePath */ #include <limits.h>		/* PATH_MAX */ #include <unistd.h>		/* execve */ #include <libgen.h>		/* dirname */ #include <string.h>		/* strcpy */

            #define BINARYNAME	"myreal_executable"

            int main(int ac, char *av[]) { 	char pathbuf[PATH_MAX + 1]; 	char real_executable[PATH_MAX + 1]; 	char *bundle_id; 	int  bufsize = sizeof(pathbuf);

            	_NSGetExecutablePath( pathbuf, &bufsize);

            	bundle_id = dirname(pathbuf);

            	strcpy(real_executable, bundle_id); 	strcat(real_executable, "/"); 	strcat(real_executable, BINARYNAME);

            	execv(real_executable, av); } --------------------

            Then write the path into /var/run/program.<pid> before you do the execv call to give control to the real binary.

            Then in your other program go looking for /var/run/program.*. When you find one, take the pid and do an atoi() on it to get the integer pid back. Then end it a kill(pid, 0).

            This function will return one of three things:

            (1) 0, indicating that the process exists and you have the right to send it signals

            (2) -1, with errno set to EPERM, indicating that the process exists and you do not have rights to send it a signal

            (3) -1, with errno set to ESRCH, indicating that the process does not (yet) exist

            -

            Ideally, all this would be unnecessary because you put your daemon and the program you want to give it a UI into the same bundle, which ,means either one of them can find the other by looking at the dirname() from their own call to _NSGetExecutablePath().

            No grovelling around trying to find out where something came from, because it tells you.

            -- Terry _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list      (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden  
            References: 
             >Find path of an application (From: "Rakesh Singhal" <email@hidden>)
             >Re: Find path of an application (From: Jean-Daniel Dupas <email@hidden>)
             >Re: Find path of an application (From: "Rakesh Singhal" <email@hidden>)
             >Re: Find path of an application (From: Jean-Daniel Dupas <email@hidden>)
             >Re: Find path of an application (From: "Rakesh Singhal" <email@hidden>)

            国产福利电影一区二区三区久久久久成人精品综合 | 丁香色欲久久久久久综合网| 国产福利电影一区二区三区久久久久成人精品综合 | 无码人妻精品一区二区三区久久| 久久这里的只有是精品23| 亚洲午夜久久久| 97久久超碰国产精品旧版| 午夜福利91久久福利| 91精品国产综合久久精品| 久久综合给合综合久久| 久久久久成人精品无码中文字幕| 久久伊人亚洲AV无码网站| 久久精品国产精品国产精品污| 久久影院亚洲一区| 色噜噜狠狠先锋影音久久| 久久水蜜桃亚洲av无码精品麻豆| 精品久久人人爽天天玩人人妻| 久久精品人成免费| 亚洲中文字幕久久精品无码喷水| 国产91久久综合| 久久婷婷久久一区二区三区| 蜜臀av性久久久久蜜臀aⅴ麻豆 | 久久99精品久久久久久久不卡 | av午夜福利一片免费看久久| 久久人人爽人人爽人人片av麻烦| 丁香五月综合久久激情| 精品午夜久久福利大片| 久久一日本道色综合久久| 久久精品国产男包| 欧美伊人久久大香线蕉综合 | 久久久久国产精品嫩草影院| 成人久久综合网| 精品免费久久久久久久| 久久久无码精品亚洲日韩蜜臀浪潮| 四虎影视久久久免费观看| 精品久久久久国产免费| 99久久精品九九亚洲精品| 91精品国产高清久久久久久91| 99久久精品免费看国产免费| 免费精品99久久国产综合精品| 2020最新久久久视精品爱|