Output when killing a background process


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Output when killing a background process
# 1  
Old 01-28-2013
Output when killing a background process

I played a bit around with the Terminal and I observed something.

When I start and kill a background process, there is some kind of output. After I invoked the command to start the process the first message "[1] 13063" is directly displayed. However, after killing the process, the second message "[1]+ Beendet sleep 20" is displayed only after I issued some other command.

Does anyone know the reason why this happens? In my case, why is "[1]+ Beendet sleep 20" displayed after I executed ps?

Code:
user@host:~$ sleep 20 &
[1] 13063
user@host:~$ ps
  PID TTY          TIME CMD
12372 pts/0    00:00:00 bash
13063 pts/0    00:00:00 sleep
13064 pts/0    00:00:00 ps
user@host:~$ kill 13063
user@host:~$ ps
  PID TTY          TIME CMD
12372 pts/0    00:00:00 bash
13065 pts/0    00:00:00 ps
[1]+  Beendet                 sleep 20
user@host:~$

PS: I use a German Ubuntu, so "Beendet" means "Terminated".
# 2  
Old 01-28-2013
Hi,

This is the default behaviour of bash. You can change it via the -b option (use set for this)

Code:
[root@host ~]# set -b
[root@host ~]# sleep 2 &
[1] 1306
[root@host ~]# [1]+  Done                    sleep 2

# 3  
Old 01-28-2013
Thanks for the quick response.

I noticed in the mean time, that this is not the case on other systems. Here is the same example from the local computing cluster (which is a CentOS machine - but I am not 100% sure)

Code:
user@cluster user> sleep 10 &
[1] 31406
user@cluster user> kill 31406
user@cluster user>
[1]    Terminated                    sleep 10
user@cluster user>

# 4  
Old 01-28-2013
Does set -b not work there? It does for me on a CentOS 6.3 system:

Code:
# set +b
# sleep 2 &
[1] 1112
#
#
[1]+ Done                      sleep 2
# cat /etc/redhat-release 
CentOS release 6.3 (Final)
# set -b
# sleep 2 &
[1] 1342
# [1]+  Done                    sleep 2

With set, confusingly, - turns it on, + turns it off (which makes sense when you think about bash being invoked with those options set). You can invoke a shell with this behaviour turned on with

Code:
# bash -b

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I send output of a background process to a file other than nohup.out?

I have a question. I will be running a background process using nohup and & command at end. I want to send output to a file say myprocess.out. So will this command work? nohup myprocess.ksh > myprocess.out & Thanks in advance guys !!! :) (3 Replies)
Discussion started by: vx04
3 Replies

2. UNIX for Dummies Questions & Answers

Seeing output of background process

I'm pretty sure I had the answer to this months ago and have misplaced it. Needless to say I will bookmark it this time. I have a background process that's been running way longer than usual. It doesn't output anything to a file, so I can't 'tail -f' it. Is there a command that will enable me to... (2 Replies)
Discussion started by: dheian
2 Replies

3. Shell Programming and Scripting

Killing the process ID's

Hi , I have a list of application process id's. Is there a way to kill all the process listed below using the script, except the once which are starting with " Genesis " adm 1522 ABC_Process.tra adm 1939 Genesis_Process.tra adm 2729 Genesis_Archive.tra adm 3259 xyz_Process.tra (5 Replies)
Discussion started by: murali1687
5 Replies

4. Shell Programming and Scripting

script killing a process from service status output

Hello, can some please suggest a script, for killing the process PID. This are steps I am currently performing to kill the process. I cant user service splunk stop, to kill these processes, because of uid and gid mismatch for splunk user. # service splunk status Splunk status: splunkd... (8 Replies)
Discussion started by: bobby320
8 Replies

5. Shell Programming and Scripting

How to put FTP process as a background process/job in perl?

Hi, I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming. So i want try putting FTP part as a background process. I am unaware how to do... (5 Replies)
Discussion started by: vanitham
5 Replies

6. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

7. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

8. Shell Programming and Scripting

Killing the Wrong Background Process

BASH on Solaris Hi All, I posted a problem whereby I was looking to Kill a background (calling Send)mail) process after a certain time had elapsed. A User Scottn very kindly provided a useful function to do this as below CheckAndKill() { sleep "$EMAIL_TIMEOUT_THEN_KILL" ... (2 Replies)
Discussion started by: satnamx
2 Replies

9. Shell Programming and Scripting

Killing of a process and send a mail if the process doesnot come up within 2 minutes

Hi Friends, I am new to this forum as well as new to shell scripting. I have a problem here and i need someone to solve this. Let us consider there are two processes(abc & def).There is a script which kills these two processes(i.e killtheprocess abc). Here abc is the argument . There is a... (1 Reply)
Discussion started by: Prince89
1 Replies

10. UNIX for Dummies Questions & Answers

killing a process

I can kill running processes on my linux red hat system using ctrl-c but cannot do it from command line of another terminal using kill -2 pid. Although I can kill them from command line using kill -9 pid and other signals. I would like to do it using the kill -2 pid. Thanks for your suggestions (6 Replies)
Discussion started by: bbhayana
6 Replies
Login or Register to Ask a Question