VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/process.cpp@ 28800

Last change on this file since 28800 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.0 KB
Line 
1/* $Id: process.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
2/** @file
3 * IPRT - Process, Common.
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
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
27
28
29/*******************************************************************************
30* Header Files *
31*******************************************************************************/
32#include <iprt/process.h>
33#include <iprt/assert.h>
34#include <iprt/err.h>
35#include <iprt/string.h>
36#include "internal/process.h"
37#include "internal/thread.h"
38
39#ifdef RT_OS_WINDOWS
40# include <process.h>
41#else
42# include <unistd.h>
43#endif
44
45
46/**
47 * Get the identifier for the current process.
48 *
49 * @returns Process identifier.
50 */
51RTDECL(RTPROCESS) RTProcSelf(void)
52{
53 RTPROCESS Self = g_ProcessSelf;
54 if (Self != NIL_RTPROCESS)
55 return Self;
56
57 /* lazy init. */
58#ifdef _MSC_VER
59 Self = _getpid(); /* crappy ansi compiler */
60#else
61 Self = getpid();
62#endif
63 g_ProcessSelf = Self;
64 return Self;
65}
66
67
68/**
69 * Attempts to alter the priority of the current process.
70 *
71 * @returns iprt status code.
72 * @param enmPriority The new priority.
73 */
74RTR3DECL(int) RTProcSetPriority(RTPROCPRIORITY enmPriority)
75{
76 if (enmPriority > RTPROCPRIORITY_INVALID && enmPriority < RTPROCPRIORITY_LAST)
77 return rtThreadDoSetProcPriority(enmPriority);
78 AssertMsgFailed(("enmPriority=%d\n", enmPriority));
79 return VERR_INVALID_PARAMETER;
80}
81
82
83/**
84 * Gets the current priority of this process.
85 *
86 * @returns The priority (see RTPROCPRIORITY).
87 */
88RTR3DECL(RTPROCPRIORITY) RTProcGetPriority(void)
89{
90 return g_enmProcessPriority;
91}
92
93
94RTR3DECL(char *) RTProcGetExecutableName(char *pszExecName, size_t cchExecName)
95{
96 if (RT_UNLIKELY(g_szrtProcExePath[0] == '\0'))
97 return NULL;
98
99 /*
100 * Calc the length and check if there is space before copying.
101 */
102 size_t cch = g_cchrtProcExePath;
103 if (cch <= cchExecName)
104 {
105 memcpy(pszExecName, g_szrtProcExePath, cch);
106 pszExecName[cch] = '\0';
107 return pszExecName;
108 }
109
110 AssertMsgFailed(("Buffer too small (%zu <= %zu)\n", cchExecName, cch));
111 return NULL;
112}
113
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