11

I'm on ubuntu 16.04 unity latest updates installed, I have one of the best Asus gaming laptops in the market, VLC is installed but I never use it.

For the last few months, I wasn't able to shut down my PC, every time I try to do so, the fans start spinning so fast and it hangs, so I just press the shut down button, that problem was only on shutdown, not restart I didn't even bother trying to solve the problem.

Today, while I was working, I noticed the fans doing the same thing that they normally do while shutting down. I ran top noticed 2 vlc instances being run under my username consuming like 122% cpu each, although again I don't use vlc, and I'm not using any program that relies on vlc.

I tried to sudo kill <pid> and sudo killall <pid> and sudo killall vlc but still they weren't killed, that never happened to me before. I killed them from Ubuntu resource monitor, they were killed and the shutdown problem was fixed, and everything went back to normal.

Did that happen to anybody before?

Lynob
  • 6,675
  • Hi, Lynob, I just updated the script in my answer in a way to be compatible with crontab, that by default works with limited number of environment variables... Now, according to my tests, the script works as it is expected. – pa4080 Jan 06 '19 at 16:01
  • @pa4080 Awesome! Thank you so much – Lynob Jan 06 '19 at 16:07
  • 2
    If you're interested in finding out why it's happening, you could run ps aux | grep " $(echo -n $(pgrep vlc | xargs ps -o ppid | tail -n +2 | tr -d ' ') | sed 's/ / \\| /g') " next time it happens. This would find all running instances of VLC, get the parent PIDs for each of them, and then search for the parent PIDs in the output of ps aux. It might help in tracking down the problem. – anonymoose Jan 06 '19 at 16:29
  • @anonymoose Thank you so much, should I get any output if VLC isn't running, because right now no vlc process is running but if I run that, I get https://pastebin.com/F4nfBnUb – Lynob Jan 06 '19 at 16:45
  • @Lynob It appears that xargs runs its command with no arguments if it doesn't receive any input, and since pgrep vlc prints nothing when VLC isn't running, it runs ps -o ppid, which lists the PPIDs for all the processes in the current terminal, and then it searches for them in the output of ps aux. The command is pretty hacky anyway (please don't use it in a script!), so I'm not going to try and fix it. It should work when VLC is running. – anonymoose Jan 06 '19 at 17:00
  • 3
    For the record, sudo kill -9 <pid> would probably have worked where just kill didn't. The -9 means "Kill anything that moves, with extreme prejudice, in the most gruesome way possible". Not much can survive it. Without -9, it's more like "Please die? Please, pretty please with a cherry on top?" – trysis Jan 06 '19 at 17:18
  • 1
    @trysis: Be careful with kill -9, it's dangerous. If for example the application has created a temporary file under /var/lock, it won't be removed. Similarly, buffers won't be flushed, database transactions will not be committed, etc. You could end up with corrupt or missing data if anything was being written anywhere. VLC is probably not doing any of those things, but I would recommend trying to understand the problem before assuming. – Kevin Jan 06 '19 at 18:19
  • 1
    BTW, 99% problems I had with VLC hanging and doing other "strange stuff" were due to it trying to use hardware acceleration for video decoding, or using the "wrong" (whatever that may mean) video backend; I'd try to fiddle with that stuff (disable HW acceleration for codecs, try to change video output backend) and see if anything good comes from it. – Matteo Italia Jan 06 '19 at 19:59

1 Answers1

10

I'm experiencing similar problem with VLC player. But the difference is I'm using it often. Here is one possible (not fully proofed) workaround for this issue on Ubuntu 16.04 with Unity.

According to this answer we can test whether there is a running application desktop file named vlc or so. If there is no one we can try to kill all VLC's processes. For this purposes create an executable file, named ~/bin/vlc-killer.sh, and add the following lines as its content (here is a reference about the exported envvars):

#!/bin/bash

# Check whether the user is logged-in: if not then exit
if [[ -z "$(pgrep gnome-session -n -U $UID)" ]]; then exit; fi

# Export the current desktop session environment variables
export $(xargs -0 -a "/proc/$(pgrep gnome-session -n -U $UID)/environ")

# Test whether there is any VLC RunningApplicationsDesktopFile
/usr/bin/qdbus org.ayatana.bamf /org/ayatana/bamf/matcher \
org.ayatana.bamf.matcher.RunningApplicationsDesktopFiles | grep -q 'vlc'

# If not killall VLC processes
if [[ $? -ne 0 ]]; then /usr/bin/killall vlc; fi

Then open the user's Crontab for edit (crontab -e) and apply the following job (that will execute our script each minute) at the bottom:

* * * * * $HOME/bin/vlc-killer.sh >/dev/null 2>&1
pa4080
  • 29,831
  • 1
    If I'm right this works only when at least one instance of vlc was started via the GUI. If you are used to run vlc movie.mpg solely from the command line (like I am) this will kill the vlc process after a minute. However, nice solution and +1 anyway. – PerlDuck Jan 06 '19 at 16:01
  • 2
    @PerlDuck, while there is an active VLC "icon" (in Dash launcher) the script works, no matter whether VLC is started by a .desktop file or by CLI. – pa4080 Jan 06 '19 at 16:14
  • 1
    Oh, cool. I wasn't aware of that. – PerlDuck Jan 06 '19 at 16:16