ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
My issue is simple yet difficult. Wondering if someone would have some insight.
Scenario: ( in C++ code)
I need a process A to be able to get the start time of process B. I have the PID of the process B.
I would have thought there would be a simple system call to make by passing in the pid of Process B, but I don't thing there is??!!
So my other thought is to create a script that will be passed the pid and either I can read the file creation of /proc/<PID>/stat or I could also parse the start time of ps on the <PID>. This script can be ran from the C++ code. My difficulty is capturing this information in the C++ code. If I run exec ( or system if not a script) I need the results in a program variable....not stdout.
Does anyone have any suggestion????
My only solution is write it to a tmp file and read it back into the program variable. Seems rather arguious but a least it would work.
Background - I need to port Windows code
( GetProcessTimes(creationtime,...))
I was already aware of the stat file. That wasn't isn't so much my issue. My main issue is getting the value into a variable within my C++ program.
I looking to confirm that there is no system call that would read the value directly into a variable within my code. If there is such a call or method or procedure, I would really be interested in knowing( I haven't been able to fine anything in my books or web).
'cat' the results into a file ( via a script) and then have the program access that temp file is my only solution right now.
The thing to remember is that, in Linux, EVERYTHING is a file.
This means that, in the vast majority of cases, you can open() (or fopen()), read(), write(), close() just like a file.
Pretty elegant in most cases, actually. You do have to be careful about the buffering that fopen/fread/fwrite/fclose do. I've found that using the lower level open/read/write/close is better when you are talking directly to the kernel or to hardware (as you are indeed doing when you talk to /proc). It makes you do more housekeeping, but keeps you out of trouble.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.