How did a command get started

7 posts / 0 new
Last post
OldFart
OldFart's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2010-11-30 14:09
How did a command get started

Hi,

I would like to know how a command was started. I.e. I want to make sure a command was started from " SYS:S/User-Startup".

My knowledge falls short again.

OldFart

cwenzel
cwenzel's picture
Offline
Last seen: 5 months 4 days ago
Joined: 2021-01-12 07:05
Re: How did a command get started

Interesting problem. The first question I have is why ?

Besides that question, you only have a couple of things to go by;
1) All commands (programs) that are "run" from a shell script will be shell processes.
(Unless you do something nutty like starting it with "WBRun" or other tricks.)
2) The commands parent PID number will be the same as the "Initial CLI" process PID.
(See also; GetPID() and ProcessScan() autodocs.)

That's about all you have that keeps launch method and the parentage info intact.
Checkout the "Ranger" tool, it gives you some valuable insight into process struct fields.

OldFart
OldFart's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2010-11-30 14:09
Re: How did a command get started

Hi,

Thanks for your clear answer. I think I can now add at least one more step in solving the puzzle.

OldFart

salass00
salass00's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 11:27
Re: How did a command get started

If you just want to check if your program was started from CLI or WB you can do so by checking the argc parameter passed to main() (== 0 for WB startup and > 0 for CLI startup).

For more details see the "Startup Code" section on the AmigaOS wiki:
https://wiki.amigaos.net/wiki/Newlib_Library#Startup_Code

OldFart
OldFart's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2010-11-30 14:09
Re: How did a command get started

@Salass00:

It is not a matter of starting either from WB or from CLI. It is a matter of starting from a very particular file (so CLI), i.e. SYS:S/User-Startup.

It seems pretty hard to obtain that info. So far I've gotten that the process's ParentID is 0, where I more or less expected it to be the ProcessID of SYS:S/Startup-Sequence. No such luck, however.

Thanks anyway,

OldFart

salass00
salass00's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 11:27
Re: How did a command get started

Unless "run" is used to execute the command asynchronously, it will be executed directly on the same process context as the script so instead of looking at GPID_PARENT you should be looking at GPID_PROCESS.

cwenzel
cwenzel's picture
Offline
Last seen: 5 months 4 days ago
Joined: 2021-01-12 07:05
Re: How did a command get started

Ok, as salass00 said, it depends on whether it is "run" or not.

For example, if the program itself is "run" from the U-S, it will have a
ParentID the same as the "Initial Cli" process, which in my case was
process 6, the same as "ramlib" ParentID, which was started from it
as well.

If the program itself is not "run" from the U-S, but executing from the
"Initial Cli" process context, it will have the same values as that process,
which in my case was ProcessID 6 again, but the ParentID will be 0,
as the "Initial Cli" was started from an exec task as the first DOS process.

Hope that explains it adequately.

Log in or register to post comments