VirtualBox

source: vbox/trunk/src/VBox/Runtime/testcase/tstRTProcIsRunningByName.cpp@ 16999

Last change on this file since 16999 was 16999, checked in by vboxsync, 16 years ago

iprt: RTProcIsRunningByName implementation for Linux.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.3 KB
Line 
1/* $Id: tstRTProcIsRunningByName.cpp 16999 2009-02-23 09:55:20Z vboxsync $ */
2/** @file
3 * IPRT Testcase - RTProcIsRunningByName
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#include <iprt/initterm.h>
36#include <iprt/stream.h>
37#include <iprt/err.h>
38#include <iprt/process.h>
39#include <iprt/param.h>
40#include <iprt/path.h>
41
42
43
44int main(int argc, char **argv)
45{
46 RTR3Init();
47
48 int rc = VERR_GENERAL_FAILURE;
49
50 char szExecPath[RTPATH_MAX] = { "vbox-5b05e1ff-6ae2-4d10-885a-7d25018c4c5b" };
51 /* Check for a definitely not running process. */
52 RTPrintf("tstRTProcIsRunningByName: Searching for a not running process with the name %s...\n", szExecPath);
53 bool fRunning = RTProcIsRunningByName(szExecPath);
54 if (!fRunning)
55 {
56 RTPrintf("tstRTProcIsRunningByName: Success!\n");
57 rc = VINF_SUCCESS;
58 }
59 else
60 RTPrintf("tstRTProcIsRunningByName: Expected failure but got success!\n");
61 /* If the first test succeeded, check for a running process. For that we
62 * use the name of this testcase. */
63 if (RT_SUCCESS(rc))
64 {
65 /* Reset */
66 rc = VERR_GENERAL_FAILURE;
67 if (RTProcGetExecutableName(szExecPath, RTPATH_MAX))
68 {
69 /* Strip any path components */
70 char *pszFilename;
71 if ((pszFilename = RTPathFilename(szExecPath)))
72 {
73 RTPrintf("tstRTProcIsRunningByName: Searching for a running process with the name %s...\n", pszFilename);
74 bool fRunning = RTProcIsRunningByName(pszFilename);
75 if (fRunning)
76 {
77 RTPrintf("tstRTProcIsRunningByName: Success!\n");
78 rc = VINF_SUCCESS;
79 }
80 else
81 RTPrintf("tstRTProcIsRunningByName: Expected success but got failure!\n");
82 }
83 else
84 RTPrintf("tstRTProcIsRunningByName: RTPathFilename failed!\n", rc);
85 }
86 else
87 RTPrintf("tstRTProcIsRunningByName: RTProcGetExecutableName failed!\n", rc);
88 }
89
90 return RT_SUCCESS(rc) ? 0 : 1;
91}
Note: See TracBrowser for help on using the repository browser.

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