From 88a98c585e97ad71d05db066229924c4d68e25db Mon Sep 17 00:00:00 2001 From: lvyuanyuan Date: Mon, 29 May 2023 12:50:19 +0000 Subject: [PATCH] =?UTF-8?q?=E9=9D=99=E6=80=81=E6=89=AB=E6=8F=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lvyuanyuan Change-Id: Ia986e0ad18769542b7634e2b7b4ad48cab7ef688 --- .../innerkits/native/file_share/src/file_share.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/interfaces/innerkits/native/file_share/src/file_share.cpp b/interfaces/innerkits/native/file_share/src/file_share.cpp index 9fa227b86..9380079c9 100644 --- a/interfaces/innerkits/native/file_share/src/file_share.cpp +++ b/interfaces/innerkits/native/file_share/src/file_share.cpp @@ -82,15 +82,19 @@ static bool IsExistFile(const string &path) static string GetPidFromProcessName(const string &processName) { FILE *fp; - const int32_t bufLen = 100; - char buf[bufLen] = {'\0'}; string cmd = CMD_GET_PID + processName; + string pid = ""; if ((fp = popen(cmd.c_str(), "r")) != NULL) { + const int32_t bufLen = 20; + char buf[bufLen] = {'\0'}; if (fgets(buf, bufLen, fp) != NULL) { - return string(buf); + pid = string(buf); } + + pclose(fp); + fp = nullptr; } - return ""; + return pid; } static int32_t GetLowerPath(string &lowerPathHead, const string &lowerPathTail, FileShareInfo &info) -- Gitee