如何在C / C ++应用程序lsof的(列出打开的文件)使用? [英] How to use lsof(List Opened Files) in a C/C++ application?

查看:112
本文介绍了如何在C / C ++应用程序lsof的(列出打开的文件)使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法让使用的 C ++ ?我知道 lsof的命令,这就是我要找的,但如何使用它在的 C ++应用程序

Is there any way to get all opened sockets using c++? I know the lsof command and this is what I'm looking for, but how to use it in a c++ application?

这样做是为了获得其口打开的插座的FD 号和 PID

The idea is to get the FD of an opened socket by its port number and the pid.

推荐答案

就在/ proc /净打开的文件,像的/ proc /网/ TCP的/ proc /净/ UDP等无需经过苦干lsof的来源。 :)

Just open the files in /proc/net, like /proc/net/tcp, /proc/net/udp, etc. No need to slog through the lsof sources. :)

这篇关于如何在C / C ++应用程序lsof的(列出打开的文件)使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆