Check if a program/script was run at startup?

19,949

Solution 1

You can look at the access time for the script. This isn't 100% reliable (since some filesystems can have noatime set). But it's usually useful for init-scripts, e.g.,

find /etc -type f -atime -1

I've found it useful for quite a while.

Solution 2

pstree will give you a detailed output of process running in a tree format.

Sample output here

init─┬─auditd───{auditd} ├─crond ├─docker─┬─10*[bash] │ ├─docker───5*[{docker}] │ ├─docker───4*[{docker}] │ ├─2*[docker───3*[{docker}]] │ ├─start-app.sh─┬─java───40*[{java}] │ │ └─tail │ ├─start-app.sh─┬─java───81*[{java}] │ │ └─tail

Share:
19,949

Related videos on Youtube

tuantm
Author by

tuantm

A former malware researcher

Updated on September 18, 2022

Comments

  • tuantm
    tuantm over 1 year

    In Linux, there are many files we can modify to add a program run at start up (/etc/rc.local, bashrc, bash_profile, $HOME/.config/autostart, ...) ? Now I have a reverse question: I have a program, can I check if this program was run during start up?

    **Note: The program can run once at start up and exit

    • jasonwryan
      jasonwryan over 7 years
      With systemd, if it was started as a service you can read the journal.
    • tuantm
      tuantm over 7 years
      Thanks @jasonwryan. That's not cover my case. The program can run just by you execute it,
    • jasonwryan
      jasonwryan over 7 years
      Then, unless it includes a logging facility, how would you expect to be able to determine if it ran or not?
    • MatthewRock
      MatthewRock over 7 years
      I suggest expanding your question. This looks like X-Y question. Why would you want to check that? Is this check looking for some speciifc program?
  • jasonwryan
    jasonwryan over 7 years
    This assumes the process is still running...
  • tuantm
    tuantm over 7 years
    Thanks @Murillo. But that is not my case, because a program can run and exit immediately so if you can't check it in process management information information
  • tuantm
    tuantm over 7 years
    Thanks @Kailas. Same as jasonwwryan said, this must assume that the process is still running.
  • Ned64
    Ned64 over 7 years
    The same informatoin can be output with stock ps: ps auf, or on modern systems with systemctl status - if the process is still running.