Page 2 of 2

Re: Get full commandline parameters

Posted: Sat Oct 03, 2015 9:36 pm
by Vera
Keya wrote:... you both seem to be suggesting that the call to /proc/self/ is creating those ~28 files
If I open the directory or use: ls -l /proc/self/

the creation-time of those files is exactly the moment when I look or use that command.
but in my Mint from the terminal i can go to any /proc/ ... say, /proc/13/ which is just one picked at random, type 'ls', and it too has all those files, like cmdline
It's the same here, and also with the creation-times of the very moment.
and i'm only calling ReadFile and ReadString... how can that be creating files? so arent they always there? or does simply the act of opening the directory actually create them?
It seems they are (re-?)-created whenever a folder within /proc/ is addressed.
So it's not your routine creating them (only initializing it), but to me it seemed so, as their creation times were the of the same time that I had run your code.

Re: Get full commandline parameters

Posted: Sat Oct 03, 2015 9:45 pm
by Keya
well i guess the Creation Date is pretty definitive! :D
ive still got a long way to go in my linux & mac for newbies books heehee, its interesting how nearly everything from a linux POV is a "file" of sorts. I certainly wasnt expecting this dynamic nature in /proc/ though, but there's a whole chapter dedicated to it lol
Thankyou very much for your testing and feedback! :)

Re: Get full commandline parameters

Posted: Sat Oct 03, 2015 10:07 pm
by Vera
Your welcome Keya.

I much appreciate your enormous heads up into these fields allowing me to benefit from your investigations. :D
... so a bit of testing & feedback is only fair and the least I can do

Re: Get full commandline parameters

Posted: Sun Oct 04, 2015 6:58 am
by Oma
Good morning @ all

Now, this is the most 'puzzling' thing i ever experienced.

GetFileAttributes("/proc/self") & #PB_FileSystem_Link works (gives 4096)
GetFileAttributes("/proc/self/cmdline") & #PB_FileSystem_Link doesn't work (4096)
and
FileSize() always has shown the length '0', even with shown commandline content :?:
[edit] i forgot:
Keya: your link-routine works as you said: works with exe, error with cmdline, even if i check "/proc/self" or "/proc/self/" :?:

If you open "/proc/self/cmdline" from filemanager the editor (Kate) shows the current process (to himself) with commandline. (Why does it exist as file or is this the link i open)
If you follow the link and open the file there's a entry from thunar (the filemanager)
I think the link and content changes in the moment i open one of the files.
wow - that's nearly like Schrödingers Cat
:lol: A good one! No no! This is Schoedingers cat :lol: ; i think he has created the theory on a Linux system. :D

The other thing you dicovered already:
The commands are separated mostly with Null. In a commandline for thunar i saw, that only the first command was shown, (the editor has shown more arguments with substitutes for Null)
Does PB stop at the first Null on ReadString and we have to use ReadData or so and how to get the real length.
An what, if the commandline starts with a Null-sign. The commandline would be shown as empty?

There remains much to be done to increase the confusion even further..

Bye, Charly

Re: Get full commandline parameters

Posted: Sat Oct 10, 2015 1:02 am
by Keya
in the book Cross-Platform Development in C++ it has an example of listing processes on Windows, Linux and Mac.
For the Linux part on page 35 these statements give me confidence im on the right track :)
Here is the Linux implementation, which uses the proc file system to obtain process information.
After opendir("/proc"):
// Read all proc contents, and record all that 1) are numeric in name, 2) are themselves directories, and 3) contain a file named "cmdline". The directory name is the PID, and the contents of cmdline is the command. This has to be slower than using sysctl(3) in BSD, and a bit more clunky, but it is the Linux way of getting process info.
inteesting it doesnt say anything about sysctl(3) in Linux, just BSD, perhaps its only available on that i dont know although i know Linux also has sysctl
The preceding code was inspired by an inspection of the sources for the top command, which confirmed that the Linux way to do this chore was to read through the proc file system.
Image