简体   繁体   English

如何计算Linux中进程的开始时间?

[英]How do I calculate start time for process in Linux?

How do I calculate the start time for a process in Linux? 如何计算Linux中进程的开始时间?

I know it's in /proc/[pid]/sched but I don't know how to retrieve/convert it. 我知道它在/proc/[pid]/sched但是我不知道如何检索/转换它。

I have looked various posts here but they're all scripting-related. 我在这里查看了各种帖子,但它们都是与脚本相关的。

You just have to fopen the file /proc/<pid>/sched and parse out the contents using fscanf or similar. 您只需要fopen文件/proc/<pid>/sched并使用fscanf或类似文件解析内容即可。 Yes, it is a lot more trouble than in a scripting language. 是的,这比脚本语言要麻烦得多。 That's life with C. 这就是C的生活。

If you want the start time of your own process, then it may be much simpler just to call gettimeofday early in your program and save the result in a global variable where other functions can access it. 如果您想要自己进程的开始时间,那么可能只是在程序中提前调用gettimeofday并将结果保存到其他函数可以访问它的全局变量中,这可能要简单得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM