VirtualBox

Changeset 17018 in vbox


Ignore:
Timestamp:
Feb 23, 2009 1:27:43 PM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
43218
Message:

RTProcIsRunningByName: spec update.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/process.h

    r16999 r17018  
    249249
    250250/**
    251  * Check if the given process is running on the system. This check is case
    252  * sensitive.
     251 * Check if the given process is running on the system.
     252 *
     253 * This check is case sensitive on most systems, except for Windows, OS/2 and
     254 * Darwin.
    253255 *
    254256 * @returns true if the process is running & false otherwise.
    255  * @param   pszName  Process name to search for.
     257 * @param   pszName     Process name to search for. If no path is given only the
     258 *                      filename part of the running process set will be
     259 *                      matched. If a path is specified, the full path will be
     260 *                      matched.
    256261 */
    257262RTR3DECL(bool)  RTProcIsRunningByName(const char *pszName);
  • trunk/src/VBox/Runtime/r3/linux/RTProcIsRunningByName-linux.cpp

    r17016 r17018  
    5252        return false;
    5353
    54     bool fFoundIt = false;
     54    bool const fWithPath = RTPathHavePath(pszName);
     55
     56    /*
     57     * Enumerate /proc.
     58     */
    5559    PRTDIR pDir;
    5660    int rc = RTDirOpen(&pDir, "/proc");
     
    99103                     * We are interested on the file name part only.
    100104                     */
    101                     char const *pszFilename = RTPathFilename(szExe);
    102                     if (RTStrCmp(pszFilename, pszName) == 0)
     105                    char const *pszProcName = fWithPath ? szExe : RTPathFilename(szExe);
     106                    if (RTStrCmp(pszProcName, pszName) == 0)
    103107                    {
    104108                        /* Found it! */
  • trunk/src/VBox/Runtime/testcase/tstRTProcIsRunningByName.cpp

    r17011 r17018  
    3838#include <iprt/param.h>
    3939#include <iprt/path.h>
     40#include <iprt/string.h>
    4041
    4142
     
    5152     * Test 1: Check for a definitely not running process.
    5253     */
    53     int rc = VERR_GENERAL_FAILURE;
    5454    char szExecPath[RTPATH_MAX] = { "vbox-5b05e1ff-6ae2-4d10-885a-7d25018c4c5b" };
    55     bool fRunning = RTProcIsRunningByName(szExecPath);
    56     if (!fRunning)
     55    if (!RTProcIsRunningByName(szExecPath))
    5756        RTPrintf("tstRTProcIsRunningByName: Process '%s' is not running (expected).\n", szExecPath);
    5857    else
     
    6362
    6463    /*
    65      * Test 2: Check for our own process.
     64     * Test 2: Check for a definitely not running process.
     65     */
     66    strcpy(szExecPath, "/bin/vbox-5b05e1ff-6ae2-4d10-885a-7d25018c4c5b");
     67    if (!RTProcIsRunningByName(szExecPath))
     68        RTPrintf("tstRTProcIsRunningByName: Process '%s' is not running (expected).\n", szExecPath);
     69    else
     70    {
     71        RTPrintf("tstRTProcIsRunningByName: FAILURE - '%s' is running! (test 1)\n", szExecPath);
     72        cErrors++;
     73    }
     74
     75    /*
     76     * Test 3: Check for our own process, filename only.
    6677     */
    6778    if (RTProcGetExecutableName(szExecPath, RTPATH_MAX))
     
    7182        if (pszFilename)
    7283        {
    73             bool fRunning = RTProcIsRunningByName(pszFilename);
    74             if (fRunning)
     84            if (RTProcIsRunningByName(pszFilename))
    7585                RTPrintf("tstRTProcIsRunningByName: Process '%s' (self) is running\n", pszFilename);
    7686            else
     
    8595            cErrors++;
    8696        }
     97
     98        /*
     99         * Test 4: Check for our own process, full path.
     100         */
     101        if (RTProcIsRunningByName(szExecPath))
     102            RTPrintf("tstRTProcIsRunningByName: Process '%s' (self) is running\n", szExecPath);
     103        else
     104        {
     105            RTPrintf("tstRTProcIsRunningByName: FAILURE - Process '%s' (self) is not running!\n", szExecPath);
     106            cErrors++;
     107        }
    87108    }
    88109    else
     
    91112        cErrors++;
    92113    }
     114
    93115
    94116    /*
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette