2

According to Bash: Special Parameters:

($!) Expands to the process ID of the job most recently placed into the background, whether executed as an asynchronous command or using the bg builtin

I can utilize this as follows:

$ leafpad &
[2] 3962
$ kill $!

This works and kills the most recent process (eg. leafpad) but for notify-send it seems not working:

$ notify-send Hello &
[2] 4052
$ kill $!
bash: kill: (4052) - No such process

And I have to use killall notify-osd in order to kill it.

So, I want to know why kill $! doesn't work for notify-send? And what is the proper way to kill such a process?

Note: I know that I can specify the time-out, but this is a different issue.

6

notify-send doesn't run for any length of time: It starts, connects to notify-osd, delivers the notification message to be displayed, and terminates.

By the time you run the kill command, notify-send has already terminated on its own. The notification you're seeing is served by notify-osd.

  • This is a more clear answer than what I had written just before; I've deleted my post & will add the links here just in case they are useful to Pandya: notify-osd discussion on Ubuntuforums. In short, notify-send is part of notify-osd, and is not running by the time you kill it, and also is supposed to only run as "notify-osd" according to NotifyOSD developer Design Specifications – forgotstackxpassword Apr 2 '16 at 15:05
  • BTW, the OP can prove this for themselves by hitting Enter again between the notify-send Hello & and the kill $!. On hitting Enter, the shell should display something like [1]+ Done notify-send Hello indicating that the job has terminated. – cas Apr 2 '16 at 22:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.