Results 1 to 5 of 5

Thread: Have any script does a command when a software loaded ?

  1. #1
    Join Date
    Jul 2020
    Beans
    363
    Distro
    Lubuntu 20.04 Focal Fossa

    Have any script does a command when a software loaded ?

    I want change cpu power profile when a software is loaded in OS memory and return to previous cpu power profile when the same software was unloaded in OS memory.
    A script does command when a software is loaded ?

    Thanks for reply.

  2. #2
    Join Date
    Aug 2011
    Location
    52.5° N 6.4° E
    Beans
    6,821
    Distro
    Xubuntu 22.04 Jammy Jellyfish

    Re: Have any script does a command when a software loaded ?

    I would use a wrapper around that software. The wrapper first changes your settings, then starts the software, waits for the software to terminate and finally restores the settings. If you want to be able to run multiple instances at the same time, add a counter and a lock so that only one instance at a time can check and update the counter.

    You could also use a script that checks for the presence of a particular process and run that script every minute, but that's a bit wasteful and slow.

  3. #3
    Join Date
    May 2010
    Beans
    3,242

    Re: Have any script does a command when a software loaded ?

    Sure. If you can find the BASH command to do it then make a script
    Code:
    command to change CPU power profile
    comamnd you want to run
    command to change CPU power profile back
    Each command waits for the previous to finish so once you close the command you want to run then the CPU power profile will be set back.

    Seems a bit excessive though and the kernel will assign more CPU to applications that need it. You could just set a lower nice value to the application to make the CPU scheduler give more time to the process you like. There isn't much detail about the exact process so I cannot give more granular advice, personally

  4. #4
    Join Date
    Jul 2020
    Beans
    363
    Distro
    Lubuntu 20.04 Focal Fossa

    Re: Have any script does a command when a software loaded ?

    Where see information about how create a wrapper or script ? What lines to add in script ?

  5. #5
    Join Date
    Mar 2010
    Location
    Squidbilly-Land
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Have any script does a command when a software loaded ?

    Quote Originally Posted by aug7744 View Post
    Where see information about how create a wrapper or script ? What lines to add in script ?
    A script is just commands that you'd type into a terminal window, but put inside a file. Then chmod u+x filename and you have a basic script.
    There are millions of example bash scripts on the internet. Millions.
    There are lots of how-to bash script guides on the internet. Thousands.

    Most of the programs on your computer are located in /usr/bin/ or /bin/ or /sbin/ or /usr/sbin/ directories. Each of those programs does something different AND they have a manpage for how to use them for the exact version installed on your system. The manpage for each is on your system IF you will be scripting, you'll need to read the manpages. Sorry. There's no way to skip that.

    If you want to browse manpages, use the xman command. There are more efficient methods, but start there.

    This is a 4-line script, so you should be able to figure it out for your needs specific to your CPU and your version of the OS. I honestly don't know the commands. If it was me, I'd use nice to prevent a long running command taking priority of the CPU. nice has a manpage, BTW. But this isn't the question you asked, so ... you'll have to look for that yourself.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •