linux文件是否被当前进程外的其他进程打开
2015-06-08 16:03
399 查看
lsof命令的用法
QProcess 调用shell命令,并获取标准输出内容:
判断文件被当前进程外的其他进程打开与否:
QProcess 调用shell命令,并获取标准输出内容:
QString pPath = "/tmp/1.txt"; QProcess commandProcess; commandProcess.start("lsof", QStringList(pPath)); commandProcess.waitForStarted(); commandProcess.waitForFinished(); QString pResult = QString(commandProcess.readAllStandardOutput());
判断文件被当前进程外的其他进程打开与否:
QStringList pidList = pResult.split("COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME").last().split("\n", QString::SkipEmptyParts); QString pidStr = QString(" " + QString::number(getpid()) + " "); for(int i=0; i<pidList.count(); i++) { if(pidList.at(i).contains(pidStr) == false) return true; } <pre name="code" class="cpp"> return false;
相关文章推荐
- linux -- 查看ip,路由,dns
- Linux ipcs命令与ipcrm命令的用法详解
- linux下的一些强力工具和桌面环境
- linux一些较为常用的发行版本
- 央视公然诽谤Linux操作系统,谁报告?
- linux(CentOS7)安装cuda
- linux 模块编程
- Linux中根据主机名获取其在局域网中的IP地址
- 动态配置脚本实现之 链接库方法提取
- linux 修改path
- linux下创建守护进程(daemon process)
- 用内存做Linux下的/tmp目录
- 解决Linux操作系统下AES解密失败的问题
- Centos 安装Puppet
- Linux
- centos7 通过kvm+vnc 实现远程桌面虚拟化和创建windows、Linux虚拟机
- linux的日志管理
- Linux 设备模型之 (kobject、kset 和 Subsystem)(二)
- Linux环境数据备份Python脚本
- centos7下配置postfix