What Are Linux Processes?
Listing Processes
Linux is a multitasking operating system, which means that more than one task can be active at once. To find out what tasks are running on your system concurrently, use the command
ps -f
UID PID PPID STIME TTY TIME COMD
hermie 24 1 00:35:28 tty1 0:01 bash
hermie 137 24 00:36:39 tty1 0:00 ps -f
The output here shows, for each active task, the UID (owning user), PID (process ID), PPID (parent process ID), STIME (when the task started), TIME (how long the task has been active), and CMD (the actual command line used to start the task). If you exa mine the PIDs and PPIDs, you can see that bash invoked the ps -f command, because the PPID of the latter matches the PID of the former.
Launching Tasks in the Foreground and Background
Suppose you have a long-running task (for example, compiling a large program) that you need to run, but you also want to get some other work done. Linux lets you start a task in the background and keep on doing other things from the command prompt. By a dding the ampersand (&) to the end of any command, you can launch it in the background and get your command prompt back right away. For example,
cc hugepgm.c > outlist &
will start cc (the C compiler) as a background task, executing it in parallel with other tasks on your system.
Note: It's a good idea to redirect the output of background tasks to a file, as shown here, since the background task still shares the console with foreground tasks. If you don't, the background task will splash any output it might produce all over your screen while you're editing a file or typing another command.
If you start a long-running task and forget to add the ampersand, you can still swap that task into the background. Instead of pressing ctrl-C (to terminate the foreground task) and then restarting it in the background, just press ctrl-Z after the command starts, type bg, and press enter. You'll get your prompt back and be able to continue with other work. Use the fg command to bring a background task to the foreground.
You might wonder why you'd ever want to swap programs between the foreground and background, but this is quite useful if for example you're doing a long-running compile and you need to issue a quick command at the shell prompt. While the compilation is running, you could press ctrl-Z and then enter the bg command to put the compiler in the background. Then do your thing at the shell prompt and enter the fg command to return the compiler task to the foreground. The ctrl-Z trick also works with the Emacs text editor and the Pine email program. You can suspend either program and then return t o your work in progress with the fg command.
Of course, in the X Windows environment, all these unnatural gyrations are not necessary. Just start another shell window and run the other command there. You can watch both processes running in separate windows at the same time, and you don't have to w orry about adding ampersands, piping output to files, or keeping track of foreground versus background processes.
LINKS TO THE OTHER TUTORIALS
Leason 1: Living in a shell
Leason 2: Root and Other Users
Leason 3: Virtual Consoles
Leason 4: Logoff and Shutdown
Leason 5: Choosing a Shell
Leason 6: The Command Prompt
Leason 7: Wildcards
Leason 8: Command History and Editing
Leason 9: Aliases
Leason 10: Redirection
Leason 11: Pipelines
Leason 12: Processes
Leason 13: Stopping a Program
Leason 14: Environment Variables
Leason 15: Help!
- Board index General Knowledge Everything Linux
-
- It is currently 03 May 2025, 17:58
- All times are UTC-04:00
Linux Basics (tutorial) #12
Discuss everything about Linux here!
Moderator: Community Moderator
- MrNiitriiX
- Premium Uploader
- Posts: 2197
- Joined: 19 Apr 2010, 14:52
- Location: between space and time
- Has thanked: 24 times
- Been thanked: 164 times
Linux Basics (tutorial) #12
Post by MrNiitriiX »
Last edited by MrNiitriiX on 31 Jul 2010, 13:03, edited 1 time in total.
Jump to
- ↳ Site Help & Support
- ↳ Site Tutorials & How To
- ↳ Site Support/Bugs
- ↳ Suggestion & Feedback
- ↳ General Discussions
- ↳ News
- ↳ Trades & Offers
- ↳ Sports
- ↳ Relax & Enjoy!
- ↳ Jokes
- ↳ General Knowledge
- ↳ Tips, Tweaks & Quick Tutorials
- ↳ OpenSource/Freeware & Useful Links
- ↳ Everything Linux
- ↳ General Support
- ↳ Technical Support
- ↳ Software Chat & Support
- ↳ Hardware Chat & Support
- ↳ Smartphones and other Portable Devices Chat & Support
- ↳ Programming/Web Building Chat & Support
- ↳ User Uploads list
- ↳ Graphics & Images
- ↳ Graphics Requests & Helpdesk
- ↳ CC Graphics & Images
- ↳ ChattChitto RG
- ↳ ChattChitto RG - Apps
- ↳ ChattChitto RG - Movies
- ↳ ChattChitto RG - Music
- ↳ Apps
- ↳ Portable
- ↳ Beta
- ↳ Games
- ↳ PC
- ↳ PS2
- ↳ PS3
- ↳ Wii
- ↳ Xbox
- ↳ PSP
- ↳ Other Consoles
- ↳ Movies
- ↳ Rips
- ↳ Pretime Releases
- ↳ DVD-Rip
- ↳ BR-Rip/BD-Rip
- ↳ 3D-Rips
- ↳ Full Rips
- ↳ DVD-R
- ↳ BR-R
- ↳ TV Shows
- ↳ HDTV Shows
- ↳ Anime/Cartoons
- ↳ Sport
- ↳ Music
- ↳ Electronic / Dance Music
- ↳ Pop / Rock Music
- ↳ Hip-Hop / Rap Music
- ↳ R&B / Soul Music / Jazz / Reggae
- ↳ Soundtrack / Classical Music
- ↳ Other Genres
- ↳ Music Videos
- ↳ DJ Mix sets & Mash-Ups
- ↳ eBooks
- ↳ Audio
- ↳ Magazine
- ↳ Mac and Other OSes
- ↳ Others
- ↳ Templates, Fonts & Scripts
- ↳ Wallpapers & Images Pack
- ↳ Tutorials - Educational Material
- ↳ Mobiles & Media Players
- ↳ Apps
- ↳ Portable
- ↳ Beta
- ↳ Games
- ↳ PC
- ↳ PS2
- ↳ PS3
- ↳ Wii
- ↳ Xbox
- ↳ PSP
- ↳ Other Consoles
- ↳ Movies
- ↳ Rips
- ↳ Pretime Releases
- ↳ DVD-Rip
- ↳ BR-Rip/BD-Rip
- ↳ 3D-Rips
- ↳ Full Rips
- ↳ DVD-R
- ↳ BR-R
- ↳ TV Shows
- ↳ HDTV Shows
- ↳ Anime/Cartoons
- ↳ Sport
- ↳ Music
- ↳ Electronic / Dance Music
- ↳ Pop / Rock Music
- ↳ Hip-Hop / Rap Music
- ↳ R&B / Soul Music / Jazz / Reggae
- ↳ Soundtrack / Classical Music
- ↳ Other Genres
- ↳ Music Videos
- ↳ DJ Mix sets & Mash-Ups
- ↳ eBooks
- ↳ Audio
- ↳ Magazine
- ↳ Mac and Other OSes
- ↳ Others
- ↳ Templates, Fonts & Scripts
- ↳ Wallpapers & Images Pack
- ↳ Tutorials - Educational Material
- ↳ Mobiles & Media Players
- ↳ Short Videos
- ↳ Regular Movies
- ↳ Hentai Movies
- ↳ Ebooks, Pics & Wallpapers
- ↳ Jokes
- ↳ Adult Sites Passwords
- ↳ Requests
- ↳ Apps requests
- ↳ Completed Requests
- ↳ Games requests
- ↳ Completed Requests
- ↳ Movies & TV Shows requests
- ↳ Completed Requests
- ↳ Music requests
- ↳ Mix Tape
- ↳ Completed Requests
- ↳ Other requests
- ↳ Mac requests
- ↳ Completed Requests
- Social Life
- ↳ Animals and Pets
- ↳ Photography
- ↳ Handy Hints for Everyday Living
- ↳ Traveling
- ↳ Motor Racing
- ↳ Cars and Bikes
- ↳ Aircrafts
- ↳ Marine/Submarine Vessels
- ↳ Cooking
- ↳ Sports
- ↳ Gadgets
- ↳ Gifts
- ↳ Forex