判断当前进程是否是Gallery3D

static bool isGalleryProcess()
{
    char cmdline[128];
    sprintf(cmdline, "/proc/%d/cmdline", getpid());
    char processName[1000];
    memset(processName, 0, sizeof(processName));
    int fd = open(cmdline, O_RDONLY);
    if (fd > 0) {
        int len = read(fd, processName, sizeof(processName));
        close(fd);
        // this name may be modified in the future
        const char* galleryProcessName = "com.android.gallery3d";
        LOGV("this process name:%s[end]", processName);
        if (len > 0 && !memcmp(processName, galleryProcessName, strlen(galleryProcessName))) {
            return true;
        }
    }
    return false;
}


你可能感兴趣的:(判断当前进程是否是Gallery3D)