Devon and Cornwall GNU/Linux Users Group

  • About DCGLUG
    • FAQ
    • Join
    • Meetings
    • Mailing List Archive
  • About : GNU / Linux
    • Federated social media
    • Video on Free software
    • Video on DRM
    • Video on Creative Commons
    • Hacker / Hacking definition
  • Tutorials
    • BASH Tutorials
    • e-learning
    • My Sql
    • LaTeX and Overleaf
    • Send Plain text e-mail
    • Tutorial : GnuPG – Encryption & Signing
  • CHAT (IRC) / Matrix
    • IRC – Client Setup
      • Weechat Setup guide
      • Hexchat Setup
      • IRSSI Configuration
      • xchat – setup
      • ERC Setup
      • Chat – Matrix
    • DCGLUG on Mastodon

Task management with fg & bg

 

Task management by Paul Sutton

In Unix / Linux operating system,  you can run a program or task from the command line and in general this will simply run and return you to the command line once completed or if you stop the program running,  this is fine,  but what happens if you want to do something else at the same time.

This is where task management comes in.

On the Raspberry pi I have created a program that controls the pi liter led board.  This consists of a small board that plugs in to the GPIO port and has 8 LEDs that can be controlled with the python for example.

I can set the program going from the command line with

sudo python cylon.py

Which is fine the led s light up and go back and forth.   however i lose control of the command line.;

But I want to carry on and have the leds do their stuff at the same time

two options are available

one is to suspend the task,  background it

so while the program is running do

ctrl-z

then type bg  This then back grounds the tasks,

to get the program back to the foreground type

fg which will then allow you to stop the process with crtl-c and do something else like run a different program

while the task is in the background you can type jobs to get a list of currently running jobs

Another way to send a program to the background is to insert an & when you run the task

sudo python cylon.py &

and when you execute it is then running in the background you can foreground the task as described above by using fg

Further reading

There is a lot more to all of this,   you can get more info from  man pages

Note however you can’t background interactive programs, so you can’t for example background a text editor as as soon as you start typing something it will come back to the foreground.

Hope this is helpful.

 
Creative Commons Licence
mint tutorials by Paul Sutton is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Leave a comment Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Tinkerers Meeting – June 2025
  • Meetings June 2025
  • End of Windows 10
  • LibreOffice 24.8.7 is available for download
  • EU security bug database

RSS Debian Security

  • DSA-5954-1 sudo - security update
  • DSA-5953-1 catdoc - security update
  • DSA-5952-1 chromium - security update

RSS Debian News

  • Updated Debian 12: 12.11 released
  • Updated Debian 12: 12.10 released
  • The Debian Project mourns the loss of Steve Langasek (vorlon)

CyberChimps WordPress Themes

© 2021 Devon and Cornwall GNU/Linux Users Group