3

This question is odd. Please note that this is not an android-studio question but a snap question. android-studio only is one culprit which misbehaves and should be restrained by snap.

android-studio was installed via snap. But sometimes processes still hang in the background and eat a lot of CPU (and hence battery power) after closing android-studio. Then I need to kill those manually using the process ID with switch -9.

Is this really the intended way? With snap?

I tried to find any pointer on Internet but failed completely how to do that with the help of snap. Either the commands do not even seem to exist or nothing helped or was completely wrong. Also snap documentation seems to hide the bit I am looking for very well (or is it missing?).

Note that all the common things are no problem at all:

But I am still puzzled how am I supposed to control an app in a snap package properly:

Well, it's snap, so everything is neatly packaged, right? And there certainly is some common easy way to fully stop everything in such a snap container, right?

For example, with lxc-stop container everything in the container is teared down. Easy. But with snap I found nothing similar.

Here is what I tried and was partially suggested by other pages:

$ snap status
error: unknown command "status", see 'snap help'.
$ snap stop android-studio
error: access denied (try with sudo)

It was started as a user, so the same user must be able to stop it again. sudo certainly is of reach here, but let's retry with sudo:

$ sudo snap stop android-studio
error: snap "android-studio" has no services
$ killall android-studio
android-studio: no process found

But with ps and top or htop there are processes (partly java, of course):

$ ps auxwww | grep android
tino       14352  0.0  0.0   2616  1732 ?        S    12:48   0:00 /bin/sh /snap/android-studio/101/android-studio/bin/studio.sh
tino       14428  4.7 10.6 5042148 420488 ?      Sl   12:48   2:19 /snap/android-studio/101/android-studio/jre/bin/java -classpath /snap/android-studio/101/android-studio/lib/bootstrap.jar:/snap/android-studio/101/android-studio/lib/extensions.jar:/snap/android-studio/101/android-studio/lib/util.jar:/snap/android-studio/101/android-studio/lib/jdom.jar:/snap/android-studio/101/android-studio/lib/log4j.jar:/snap/android-studio/101/android-studio/lib/trove4j.jar:/snap/android-studio/101/android-studio/lib/jna.jar:/snap/android-studio/101/android-studio/jre/lib/tools.jar -Xms256m -Xmx1280m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -XX:CICompilerCount=2 -Dsun.io.useCanonPrefixCache=false -Djdk.http.auth.tunneling.disabledSchemes="" -Djdk.attach.allowAttachSelf=true -Dkotlinx.coroutines.debug=off -Djdk.module.illegalAccess.silent=true -Djna.nosys=true -Djna.boot.library.path= -Didea.vendor.name=Google -Dawt.useSystemAAFontSettings=lcd -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -Dsun.tools.attach.tmp.only=true -XX:ErrorFile=/home/tino/java_error_in_STUDIO_%p.log -XX:HeapDumpPath=/home/tino/java_error_in_STUDIO.hprof -Didea.paths.selector=AndroidStudio4.1 -Djb.vmOptionsFile=/snap/android-studio/101/android-studio/bin/studio64.vmoptions -Didea.platform.prefix=AndroidStudio -Didea.jre.check=true com.intellij.idea.Main
tino       45016  0.0  0.0  11128  2452 pts/12   S+   13:37   0:00 grep --color=auto android
$ kill 14352
$ kill 14352
-bash: kill: (14352) - No such process
$ kill 14428
$ kill 14428
$ ps auxwww | grep android
tino       14428  4.7 10.6 5042148 420488 ?      Sl   12:48   2:19 /snap/android-studio/101/android-studio/jre/bin/java -classpath /snap/android-studio/101/android-studio/lib/bootstrap.jar:/snap/android-studio/101/android-studio/lib/extensions.jar:/snap/android-studio/101/android-studio/lib/util.jar:/snap/android-studio/101/android-studio/lib/jdom.jar:/snap/android-studio/101/android-studio/lib/log4j.jar:/snap/android-studio/101/android-studio/lib/trove4j.jar:/snap/android-studio/101/android-studio/lib/jna.jar:/snap/android-studio/101/android-studio/jre/lib/tools.jar -Xms256m -Xmx1280m -XX:ReservedCodeCacheSize=240m -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -XX:CICompilerCount=2 -Dsun.io.useCanonPrefixCache=false -Djdk.http.auth.tunneling.disabledSchemes="" -Djdk.attach.allowAttachSelf=true -Dkotlinx.coroutines.debug=off -Djdk.module.illegalAccess.silent=true -Djna.nosys=true -Djna.boot.library.path= -Didea.vendor.name=Google -Dawt.useSystemAAFontSettings=lcd -Dsun.java2d.renderer=sun.java2d.marlin.MarlinRenderingEngine -Dsun.tools.attach.tmp.only=true -XX:ErrorFile=/home/tino/java_error_in_STUDIO_%p.log -XX:HeapDumpPath=/home/tino/java_error_in_STUDIO.hprof -Didea.paths.selector=AndroidStudio4.1 -Djb.vmOptionsFile=/snap/android-studio/101/android-studio/bin/studio64.vmoptions -Didea.platform.prefix=AndroidStudio -Didea.jre.check=true com.intellij.idea.Main
tino       45020  0.0  0.0  11128  2544 pts/12   S+   13:37   0:00 grep --color=auto android
$ kill -9 14428
$ kill -9 14428
-bash: kill: (14428) - No such process

Apparently some are die-hards and need -9 to be killed!

Notes:

  • I do not want to use killall java, because this will affect other java applications.
  • Of course I could create some script, which looks into /proc to sort out processes which belong to snap and operate on this.
  • But I am looking for a command which involves snap instead of re-inventing the wheel with some independent external command based on internals of snap.
  • I ask this on AskUbuntu, because I only use snap on Ubuntu
1

2 Answers 2

0

snap is a system for application distribution and installation. Processes spawned from a program installed as a snap are no different from processes of any other software running on the system, and thus are to be managed identically.

In other words, there is nothing specific to processes that are associated with software installed as a snap. Each software package causes one or more processes to be started. Which ones these are are specific to the software.

Thus, no general answer can be given on the question "how to stop processes of a snap package". This comment equally applies if you leave out the word "snap". So really, a specific answer is only possible for specific software.

2
  • 1
    I feared exactly that
    – Tino
    Apr 6, 2021 at 9:14
  • 1
    "snap is a system for application distribution and installation." - and confinement. "Processes... [of]... a snap are no different from processes" - Is that true? they are set up in cgroups aren't they? they are in independent sessions aren't they? I got here because a snap packages (graphical) process isn't responding to "force-kill" requests the way native ones do. Is it just coincidence? Additionally I can't find the specific process with ps fuax.
    – Greg
    Jul 7, 2021 at 23:49
0

If snap refuses to refresh something because it has running processes, you can tease out exactly what they are by running this:

# snap refresh my-awesome-app

If there are running processes, it will respond with something similar to this:

error: cannot refresh "my-awesome-app": snap "my-awesome-app" has running apps (my-awesome-app), pids:
       1210273,1210277,1210278

You can kill them: kill 1210273 1210277 1210278

After that, try snap refresh again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .