1

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

2 Answers 2

0

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.

2
  • Thanks for your reply. So basically, it's the & that makes it launch in the background ?
    – Ezhno
    Aug 7, 2017 at 13:20
  • 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.
    – Oli
    Aug 7, 2017 at 13:25
0

I would do it this way:

chromium-browser www.youtube.com -start-fullscreen &; pid=$!; sleep 1m; kill -15 $pid

tested and it works

If you want to be 100% sure it closes, you may be more brutal and do kill -9 $pid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.