Running programs in the background from terminal

1

When running programs from an terminal window in Ubuntu, the program process will run in the foreground, occupying the terminal session that started the program. Until the program ends or is closed, you can not start other applications as long as this process is running in the foreground. While you can open another terminal window or use the screen command, Bash shell provides an easier function known as job control that will allow multiple programs to run in the background and return control to the terminal window on Ubuntu. To use job control and allow programs to return control back to the terminal window, commands entered should be followed with the ampersand character &

For example, you want to open Firefox. From the command line you would type:

firefox &

Firefox will open in the background and the terminal window control will be returned allowing you to continue working in the terminal window. If you want to open another program or run a script, you...

0 0
2
I

am a new Linux command line user. How do I start or run command in the background so that I can access command prompt immediately?


A command that has been scheduled

nonsequentially is called background process

. You can not see the background processes on screen. For example, Apache httpd server runs in background to serve web pages. You can put your shell script or any command in background.

Syntax

You can put a task (such as command or script) in a background by appending a & at the end of the command line. The & operator puts command in the background and free up your terminal. The command which runs in background is called a job. You can type other command while background command is running. The syntax is:

Examples

Put the ls command in the background, enter:
$ ls *.py > output.txt &
Put the following find command in a background by putting a ‘&’ at the end of the command line:

Sample outputs:

...
0 0
3
Howto: Run Program from Terminal as Background Process

location: ubuntuforums.com - date: August 4, 2011
Hi, everyone! This is my first post in these forums, so before I go on, I'd just like to thank all the good people that contribute to the Ubuntu community. I started using Ubuntu about a month ago, and so far these forums have answered every question I've had. What I wanted to share now is a simple trick I discovered from another website (http://www.linux-tutorial.info/modul...ntent&pageid=3). I couldn't find this trick in these forums, so I decided to share it with you guys. If you use the terminal, you know that when you type the command to run a program, the program opens, but the terminal's command prompt will not reappear until you close the program. This can be kind of annoying in some cases, so I will explain how to run a program as a background process. First, open up your terminal, and go to the directory containing the program you wish to run. Suppose the...

0 0
4

From MobileRobots Research and Academic Customer Support

Normally, a program run on Linux from the command shell is attached to the terminal session from which it was started. It will send output to that terminal, read input including keystroke events, and if that terminal session ends for any reason, the program is automatically terminated as well.

This means that if you are remotely logged in to a robot's onboard computer over ssh (e.g. using Putty on Windows), if the network connection fails for any reason (wifi signal drops, you shut down the remote computer, etc.), the program running on the robot's onboard computer will be terminated as well.

In order to avoid this, you need to do three things:

1. remove any use of raw keyboard input events from the program

The only way to prevent use of raw keyboard input events (1) is to remove or disable this in the program code itself. For example, ARIA's demo example, and some other example...

0 0
5

If you’re like most Windows users, you have lots of great little utilities that run when you start Windows. While this works great for most apps, there are some that would be nice to start even before a user logs in to the PC. To do this, you’ll need to run the app as a Windows service.

Windows services are a special class of programs that are configured to launch and run in the background, usually without any sort of user interface and without needing a user to log in to the PC. Many gamers and power users know them as those things you used to disable to help speed up your system, though that’s really not necessary any more.

The primary advantage of running an app as a service is that you can have a program start before a user to log in. That can be particularly important with apps that provide important services you want to be available when you’re away from your computer.

A perfect example of this is Plex, a media server app that can stream local...

0 0
6

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.

We will see in this article how to send commands in the background, then return them to the foreground, and make sure that also closing the current shell or terminal the process doesn’t remains tied to the session but continue to work.

An alternative to these command is using screen, as read in a former article, but now let’s see the command bg and the special character &

Task 1 : start a process directly in background

sleep 100 &

This will start the sleep as a background task, executing it in parallel with other tasks on your system, the special character & after the commandmeans that.

There is no output and you’ll be back at command prompt, after 100 seconds you’ll get

[1]+ Done sleep...

0 0
7

There are a variety of ways to see all applications or programs which are running on a Mac, ranging from only seeing “windowed” apps running in the graphical front end, to revealing even the most obscure system-level processes and tasks running at the core of OS X. We’ll cover five different ways to view these running apps and processes in Mac OS X, some of which are very user friendly and applicable to all users, and some of which are more advanced methods accessible from the command line. Take the time to learn them all, and you can then use the method most appropriate for your needs.

At a Glance: Looking at the Dock

The simplest way to see what apps are running at the moment is to just glance at the OS X Dock. If you see a little glowing dot under the application icon, it’s open and running.

Though there’s nothing wrong with using this approach, it’s obviously a bit limited since it only shows what are called “windowed” apps – that is, apps...

0 0
8

Important Security Advisory 06/07/2016

On June 6th, 2016, BitTorrent was made aware of a security issue involving the vendor which powers our forums.
The vulnerability appears to have been through one of the vendor’s other clients, however it allowed attackers to access some information on other accounts. As a result, attackers were able to download a list of our forum users. We are investigating further to learn if any other information was accessed.Our vendor has made backend changes so that the hashes in the file do not appear to be a usable attack vector. As a precaution, we are advising our users to change their passwords. While the passwords may not be used as a vector on the forums, those hashed passwords should be considered compromised. Anyone using the same password for forums as well as other places is strongly advised to update their passwords and/or practice good personal security...

0 0
9

I've recently come to like setsid. It starts off looking like you're just running something from the terminal but you can disconnect (close the terminal) and it just keeps going.

This is because the command actually forks out and while the input comes through to the current terminal, it's owned by a completely different parent (that remains alive after you close the terminal).

An example:

setsid gnome-calculator

I'm also quite partial to disown which can be used to separate a process from the current tree. You use it in conjunction with the backgrounding ampersand:

gnome-calculator & disown

I also just learnt about spawning subshells with parenthesis. This simple method works:

(gnome-calculator &)

And of course there's nohup as you mentioned. I'm not wild about nohup because it has a tendency to write to ~/nohup.out without me asking it to. If you rely on that, it might be for you.

nohup gnome-calculator

And for the longer-term processes,...

0 0
10

Watch in 1080p HD for optimal clarity! All commands used are listed below for your convenience.

In this video I demonstrate through the use of screen captures and narration how to compile and run Java programs using the Windows Command Prompt and the Ubuntu Unix Terminal. No IDE is required for the compilation and execution process - compilation and execution can be performed via the Command Prompt and the Terminal.

I'll also demonstrate how to install and set up the Oracle Java Development Kit (JDK) on Windows and Ubuntu systems, as well explain briefly what a JDK is. To compile and run Java programs, we require the Java Compiler, the Java Virtual Machine and the Java Standard Library, all of which are included in the JDK, hence the JDK is absolutely essential for our purposes.

I hope you learn something new from this video tutorial, and if you like it, please like, comment and subscribe!

----- Download Link for JDK -----
Download x64 installer if...

0 0
11

Everyone’s been there: you’re looking to run a terminal program and keep it running. The trouble is this program is old or doesn’t include a feature that allows it to run as a daemon in the background. Luckily, there are several ways to force programs to work in the background anyway.

Bash can do this all on its own, and extra programs will not need to be installed. This article will go over several ways that you can push terminal programs into the background and keep them there. Each method listed is good for its own special-use case.

If you want to push a command into the background, using & at the end is an easy way to do that. It comes with a catch, though. Using & doesn’t disconnect the command away from you; it just pushes it in the background so you can continue using a terminal.

When the terminal session is closed, the command ends. Using & is good if you need to push something off for a bit, but don’t expect it to continue forever.

Running a...

0 0
12

Auto running applications in the GUI

See here

Auto running terminal applications (non GUI)

First ensure your program is executable by finding it in the file manager. Right click on the file and select properties. Select the permissions tab, check the ‘Make the file executable’ box and press OK. Or from the command line use:

sudo chmod +x /home/pi/projects/my_project.a

Or using a different tool set its chmod to 755 (rwxr-xr-x). It doesn't matter if the user is root.

Doesn't work?

We've found that when copying a new file to the rpi using WinSCP, changing its properties to 755 and verifying all is OK that if we kill the power and power up again the executable doesn't run. However if we use sudo reboot at the command line it works as it should. It seems there is some sort of caching action going on so after doing this use sudo reboot the first time rather than cycling the power!

You can setup the auto run...

0 0
13
...
0 0
14

As you can probably tell there are lots of ways to do this.

Regarding your "UPDATE #2" -- generally speaking, terminating any process in a parent-child hierarchy will generally terminate all the associated processes. But there are many exceptions to this. Ideally you want to terminate the final 'child' in a process tree, then the parent(s) of this child should exit if they have no other tasks to run. But if you kill a parent, the signal should be relayed down to children when the parent dies and the children should exit as well -- but there are cases where the children processes may ignore the signal (via traps or similar mechanisms) and may continue to run an will be inherited by the 'init' process (or similar.) But this subject of process behavior can get complex and I'll just leave it there...

One method I like if I don't want to use a control script (described next) is to use the 'screen' utility to start and manage the process. The 'screen' command is full of...

0 0
15

By Gary Newell

This is a short but useful guide to show how to run Linux applications from the terminal whilst allowing the terminal to retain control.


There are various ways of opening a terminal window in Linux and it largely depends on your choice of distribution and the desktop environment.

Using Ubuntu you can open a terminal by using the CTRL + ALT + T key combination. You can also open a terminal window by pressing the super key (Windows Key), on the keyboard, to bring up the Dash and search for "TERM". Clicking on the "Term" icon will open a terminal window.

For other desktop environments such as XFCE, KDE, LXDE, Cinnamon and MATE you will find the terminal within the menu. Some distributions will have a terminal icon in a dock or as a launcher on a panel.

You can generally start an application from the terminal by simply entering the name of the program. For instance you can start Firefox by typing "firefox".

The...

0 0
16

When I started with $ nohup storm dev-zookeper ,

METHOD1 : using jobs,

prayagupd@prayagupd:/home/vmfest# jobs -l [1]+ 11129 Running nohup ~/bin/storm/bin/storm dev-zookeeper &

METHOD2 : using ps command.

$ ps xw PID TTY STAT TIME COMMAND 1031 tty1 Ss+ 0:00 /sbin/getty -8 38400 tty1 10582 ? S 0:01 [kworker/0:0] 10826 ? Sl 0:18 java -server -Dstorm.options= -Dstorm.home=/root/bin/storm -Djava.library.path=/usr/local/lib:/opt/local/lib:/usr/lib -Dsto 10853 ? Ss 0:00 sshd: vmfest [priv]

TTY column with ? => nohup running programs.

Description

TTY column = the terminal associated with the process STAT column = state of a process S = interruptible sleep (waiting for an event to complete) l = is multi-threaded (using CLONE_THREAD, like NPTL pthreads do)

Reference

$ man ps # then search /PROCESS STATE...

0 0