Launching Chromium via Terminal, waiting some times, and close it

18,133

You're right, when you run something in the foreground —unless it forks out itself­— it blocks flow. The answer would logically be to stick chromium in the background, and allow the rest of your commands to continue. You can do that with a single &

chromium-browser ... & sleep 1m; pkill --oldest chromium

There are other considerations to think about here when dealing with something as complicated as Chrom{e,ium}. They tend to fork out into monster processes and killing the head might not kill them all. If you're getting any gyp from the above, I'd switch to killall chromium.

And that all said, I've just learnt about the timeout command. Yeah, still learning. This simplifies the syntax and will even let you leave something in the foreground (useful for interactive terminal stuff).

timeout 1m chromium-browser www.youtube.com -start-fullscreen

This sends SIGTERM by default but you can tune it. See man timeout.

Share:
18,133
Ezhno
Author by

Ezhno

Updated on September 18, 2022

Comments

  • Ezhno
    Ezhno almost 2 years

    I've got an issue with my simple command line : chromium-browser www.youtube.com -start-fullscreen; sleep 1m; pkill --oldest chromium

    As you figured out, I would like to launch Chromium with chromium-browser www.youtube.com -start-fullscreen (tried it alone and it worked) Then wait 1Minute with : sleep 1m And then close my browser with pkill --oldest chromium (Also tried it alone and it worked). All that from the terminal.

    Unfortunately my script doesn't work. It does launch my chromium on www.youtube.com but it doesn't close it after one minute.

    I believe this can be from the fact that when the browser is launched, the terminal only listen to the software and is not able to execute any more commands, correct ?

    So, how can I launch this script so that it would past the browser launch ?

    Thanks in advance

  • Ezhno
    Ezhno almost 7 years
    Thanks for your reply. So basically, it's the & that makes it launch in the background ?
  • Oli
    Oli almost 7 years
    Yeah. It's still tied to the context it was created in (eg if you ran it from a terminal with & and closed it, it'd close, see ... & disown for fixing that if that's ever a problem) but it goes off into the background where it won't stop flow.