Tag Info

Hot answers tagged

35

It is in the ! shell variable: my-app & echo $!


24

There are many ways to go about this. Method #1 - ps You can use the ps command to find the process ID for this process and then use the PID to kill the process. Example $ ps -eaf | grep [w]get saml 1713 1709 0 Dec10 pts/0 00:00:00 wget ... $ kill 1713 Method #2 - pgrep You can also find the process ID using pgrep. Example $ pgrep wget ...


23

By default the terminal will run the program in the foreground, so you won't end up back at the shell until the program has finished. This is useful for programs that read from stdin and/or write to stdout -- you generally don't want many of them running at once. If you want a program to run in the background, you can start it like this: $ lxpanel & ...


14

From Bash's man page: ! Expands to the process ID of the most recently executed background (asynchronous) command. So $! would contain the process ID (PID) of the last job that was backgrounded. Example $ sleep 100 & [1] 18813 $ echo "$!" 18813 References bash man page


13

$! contains the process ID of the most recently executed background pipeline. From man bash: Special Parameters The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed. ... ! - Expands to the process ID of the most recently executed background (asynchronous) ...


12

Put \j in your prompt. From the bash manual: \j The number of jobs currently managed by the shell Just remember that prompts do go stale and jobs can finish at any time, so if you have left the terminal idle, you'll want to redisplay the prompt. At the cost of requiring an extra process just to print your prompt, you can make the \j only ...


12

The easiest way is to run fg to bring it to the foreground: $ help fg fg: fg [job_spec] Move job to the foreground. Place the job identified by JOB_SPEC in the foreground, making it the current job. If JOB_SPEC is not present, the shell's notion of the current job is used. Exit Status: Status of command placed in foreground, or ...


12

You can use jobs to list the suspended process. Take the example. Start with a process: $ sleep 3000 Then you suspend the process: ^Z [1]+ Stopped sleep 3000 You can list the process: $ jobs [1]+ Stopped sleep 3000 and bring it back to the foreground: $ fg %1 sleep 3000 The %1 corresponds to the [1] listed ...


10

You can run this command to remove all the jobs at the atq for i in `atq | awk '{print $1}'`;do atrm $i;done


10

You could do something like this: for i in $(atq | cut -f 1); do atrm $i; done


10

In bash you can use fg to get the job to the foreground and then use Ctrl+C Or list the process in the background with jobs and then do kill %1 (with 1 replaced by the number jobs gave you)


8

Your background job continues executing until someone tells it to stop by sending it a signal. There are several ways it might die: When the terminal goes away for any reason, it sends a HUP signal (“hangup”, as in modem hangup) to the shell running inside it (more precisely, to the controlling process) and to the process in the foreground process group. A ...


7

The jobs are not killed, they are suspended. They remain exactly as they are at the time of the suspension: same memory mapping, same open file, same threads, … It's just that the process sits there doing nothing until it's resumed. It's like when you pause a movie. A suspended process behaves exactly like a process that the scheduler stubbornly refuses to ...


6

If you type command 1 & command 2 this is equal to command 1 & command 2 i.e. this will run the first command in background and then runs the second command in foreground. Especially this means, that your echo "done" is printed after command 2 finished even if command 1 is still running. You probably want command 1 & command 2 & wait ...


6

jobs is not a real command, but a command that is builtin to the shell that you're using: martin@dogmeat:~$ type jobs jobs is a shell builtin When you try to run it without a shell, you'll get an error message, because there is no binary executable called jobs. It also doesn't have a manpage because it's just a builtin. Look in man builtins as Marco ...


6

If the terminal you launched the command from is still open, you can get it back by running fg. If it is not, identify the process ID by running ps aux | grep yum or just pgrep yum and then use kill PID. Or, if you know you only have one yum instance, run pkill yum.


5

When you start a program in a terminal, the terminal will "hang" until your program stops. By pressing Ctrl+c you are closing your program, and thus get back to the prompt. You will see this with all GUI apps, try Firefox, for example. When you use some other method such as Alt+F2 or clicking through the menus, your program is started in the background so ...


5

This is possible in zsh, and in fact it's easy thanks to the direct access to the job parameters provided by the zsh/parameter module. You can use a job number or any job specification (%+, %-, %foo, etc.) as a subscript in the array. zmodload zsh/parameter fgcd () { local dir=$jobdirs[${1:-%+}] # If the jobspec matched, then call cd. Otherwise it's ...


5

From a user's perspective, it means that the job is paused. It will no longer use any CPU. It will, however, keep using the same amount of RAM. That is why you can bring it back to the foreground with fg and it will continue where it left off. If you kill a job and then restart it, it will start over from scratch.


5

Yes, all you need to know is the process id (PID) of the process. You can find this with the ps command, or the pidof command. kill $(pidof ping) Should work from any other shell. If it doesn't, you can use ps and grep for ping.


5

After a process is sent to the background with &, its PID can be retrieved from the variable $!. The job IDs can be displayed using the jobs command, the -l switch displays the PID as well. $ sleep 42 & [1] 5260 $ echo $! 5260 $ jobs -l [1] - 5260 running sleep 42 Some kill implementations allow killing by job ID instead of PID. But a ...


4

If you type top in the another terminal window, it'll list the all the process running. Note the process id of your job there, Then press q to leave that screen. Then kill the process as usual.


4

If your intent is to get the working directory of a process, this is one way: ~ » jobs -l [1] + 14308 running sleep 1h ~ » readlink /proc/14308/cwd /home/matti-nillu The following function inside .bashrc, will do exactly what you want cdjob () { pid=$(jobs -p $1); d=$(readlink /proc/$pid/cwd); cd "$d" } Example: ~$ sleep 1h & [1] ...


4

EDIT: Once in the foreground, you can Ctrl+C, or as @Zelda mentions, kill with the '%x' where 'x' is the job number will send the default signal (most likely SIGTERM in the case of Linux). just type fg to bring it to the foreground, if it was the last process you backgrounded (with '&'). If it was not the last one, type: jobs and find the 'job number', ...


3

Programs run via a shell run in the foreground of that shell by default. This causes the shell to suspend operation and direct stdin/stdout/sterr from the terminal to the program. Programs run via the desktop environment are forked, which causes them to run independent of the program that ran them. This can be simulated in most shells by appending a & to ...


3

You have two options, I think: $BASHPID or $! echo "version: $BASH_VERSION" function abc() # wait for some event to happen, can be terminated by other process { echo "inside a subshell $BASHPID" # This gives you the PID of the current instance of Bash. sleep 3333 } echo "PID: $$" # (i) abc & echo "PID: $$" # (ii) echo "another way ...


3

You can use kill -STOP pid to pause a job and kill -CONT pid to resume it. You get the proper pid from the ps command you already know.


3

This is a tad tricky because of quoting, note change from " to ' The following will work if you submit your at job via at -f file at -f nc.on now cat nc.on bash -c 'while [ 1 ]; do echo $$ > /var/run/atnc.pid; nc -l -p 1111 >> check; done' the file /var/run/atnc.pid will have the process id of the bash which is running nc You can cat the file ...


3

You can use batch program that is part of at package (tools for job queuing). It is installed by default on many systems.


3

If the issue is you're finding it difficult to keep track of what you're working on as you bounce from task to task you might want to take the time to look at using a tool such as tmux and/or screen. These are virtual terminal window servers and allow you to setup a terminal within them and name it. This allows you to put some context on a terminal and keep ...



Only top voted, non community-wiki answers of a minimum length are eligible