1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "process_helper.h" 17 18 #include <cstdint> 19 #include <sys/resource.h> 20 #include <sys/time.h> 21 #include <sys/sysinfo.h> 22 23 namespace Commonlibrary::Platform { 24 ProcessExit(int signal)25void ProcessExit(int signal) 26 { 27 quick_exit(signal); 28 } 29 GetSysConfig(int number)30int GetSysConfig(int number) 31 { 32 auto configinfo = static_cast<int32_t>(sysconf(number)); 33 return configinfo; 34 } 35 GetSysTimer()36double GetSysTimer() 37 { 38 struct sysinfo information = {0}; 39 time_t systimer = 0; 40 if (sysinfo(&information)) { 41 HILOG_ERROR("Failed to get sysinfo"); 42 return SYS_INFO_FAILED; 43 } 44 systimer = information.uptime; 45 return static_cast<double>(systimer); 46 } 47 GetThreadId()48int GetThreadId() 49 { 50 auto proTid = static_cast<int64_t>(gettid()); 51 return proTid; 52 } 53 GetThreadPRY(int tid)54int GetThreadPRY(int tid) 55 { 56 int32_t pri = getpriority(PRIO_PROCESS, tid); 57 return pri; 58 } 59 } // namespace Commonlibrary::Platform