1 2 // Copyright (C) 2022 Google Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 #include "aemu/base/Process.h" 17 18 #if defined(__linux__) 19 #include <fstream> 20 #endif 21 #include <string> 22 23 namespace gfxstream { 24 namespace guest { 25 getProcessName()26std::string getProcessName() { 27 // Support for "getprogname" function in bionic was introduced in L (API level 21) 28 std::string processName; 29 #if defined(__ANDROID__) && __ANDROID_API__ >= 21 30 processName = std::string(getprogname()); 31 #elif defined(__linux__) 32 { 33 std::ifstream stream("/proc/self/cmdline"); 34 if (stream.is_open()) { 35 processName = std::string(std::istreambuf_iterator<char>(stream), 36 std::istreambuf_iterator<char>()); 37 } 38 } 39 #endif 40 return processName; 41 } 42 43 } // namespace guest 44 } // namespace gfxstream