Chromium Code Reviews| Index: base/process_info_mac.cc |
| diff --git a/base/process_info_mac.cc b/base/process_info_mac.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7a1e733d517e792042f70e83fb41d1db3bb64898 |
| --- /dev/null |
| +++ b/base/process_info_mac.cc |
| @@ -0,0 +1,39 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "base/process_info.h" |
| + |
| +#include <sys/sysctl.h> |
| +#include <sys/time.h> |
| +#include <unistd.h> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/time.h" |
| + |
| +namespace base { |
| + |
| +//static |
| +const Time* CurrentProcessInfo::CreationTime() { |
| + static Time process_creation_time; |
| + static bool process_creation_time_initialized = false; |
| + |
| + if (!process_creation_time_initialized) { |
| + int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() }; |
| + size_t len = 0; |
| + if (sysctl(mib, arraysize(mib), NULL, &len, NULL, 0) < 0) |
| + return NULL; |
| + |
| + scoped_ptr_malloc<struct kinfo_proc> |
| + proc(static_cast<struct kinfo_proc*>(malloc(len))); |
| + if (sysctl(mib, arraysize(mib), proc.get(), &len, NULL, 0) < 0) |
| + return NULL; |
| + process_creation_time = |
| + base::Time::FromTimeVal(proc->kp_proc.p_un.__p_starttime); |
| + process_creation_time_initialized = true; |
| + } |
| + return &process_creation_time; |
|
Mark Mentovai
2012/06/15 21:18:57
Oh no! This is no good at all.
|
| +} |
| + |
| +} // namespace base |