Linux 上进程的启动时间
如何使用c语言在ubuntu linux机器上查找进程启动时间。在linux中,/proc/[pid]/stat文件提供了信息
starttime %lu /*系统启动后进程启动的时间(以jiffies为单位)*/
和文件 /proc/stat 给出了
btime %lu /*measurement of system boot time since Epoch in seconds*/
要添加这两个值,我如何将前一个值转换为秒,因为它以 jiffies 为单位。
How to find a process start time on ubuntu linux machine using c language. In linux there is /proc/[pid]/stat file which give information
starttime %lu /*The time in jiffies the process started after system boot*/
and file /proc/stat that gives
btime %lu /*measurement of system boot time since Epoch in seconds*/
For adding both these values how can I convert former value into seconds because it is in jiffies unit.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当编译 Linux 内核时,每秒的 Jiffies 是可配置的。
以下程序使用您正在运行的内核上每秒的 jiffies 数。它需要一个可选的命令行参数,即进程号。默认是正在运行的程序本身的进程号。它每秒输出指定进程的开始时间,包括本地时间和 UTC 时间。重复循环的唯一原因是证明该值不会改变。
Jiffies per second is configurable when one compiles the Linux kernel.
The following program uses the number of jiffies per second on the kernel you're running. It takes an optional command line parameter, which is the process number. The default is the process number of the running program itself. Each second, it outputs the start time of the specified process, both as local time and UTC. The only reason for the repeat loop is to demonstrate that the value doesn't change.