I need a way to kill all the processes used in the script below. I removed all the unnecessary code and made it as simple as I can, without ruining the structure.  I made the kill_other function for that, which when called (after CTRL + C is pressed) is suppose to kill everything.  Right now if I kill the script, functionOne and adb logcat continue running.  How can I kill them?  Also, since I'm fairly new to the trap function I have to ask have I positioned it correctly in the code?  EDIT : I am running this script on Ubuntu 19.04 and my target is an Android phone, if someone needs the info.  #!/bin/sh  kill_other(){     ## Insert code here to kill all other functions     exit }  trap 'kill_other' SIGINT  main(){      functionOne &amp;      adb logcat &gt; log_test.log &amp;      while true         do             echo "==================================================================="             memPrint             sleep 10         done }  functionOne(){     while true         do             sleep 20             echo "==================================================================="             echo "Starting app 1"             echo "==================================================================="             functionTwo              sleep 20             echo "==================================================================="             echo "Starting app 2"             echo "==================================================================="             functionThree         done }  functionTwo(){     adb shell monkey -p com.google.android.youtube -c android.intent.category.LAUNCHER 1 }  functionThree(){     adb shell monkey -p tv.twitch.android.app -c android.intent.category.LAUNCHER 1 }  memPrint(){     adb shell dumpsys meminfo | grep -A 10 "Total PSS by process\|Foreground\|Perceptible\|Total RAM\|Home" }  ## Start main
I am looking for a way to clean up the mess when my top-level script exits.  Especially if I want to use set -e, I wish the background process would die when the script exits.
How do I get the MAX row with a GROUP BY in LINQ query? Full URL not working with php include Primary ideals in Noetherian rings What are the correct version numbers for C#? Distance Between Two Points in Matlab Getting the name of the currently executing method Is there a way to get the name of the currently executing method in Java? Let G be a finitely generated abelian group and M a compact manifold,  I want to prove that $H_r(M,G)$ is finitely generated for $r\ge 0 $.  First I was thinking if  I could do induction over $r$ because for $r=0$, $H_0(M,G) \cong \bigoplus_{i=1}^nG$ where $n$ denotes the number of connected components of M.But for $r&gt;0$ I can't see a way to relate $H_r(M,G$) and $H_{r+1}(M,G)$.  Then I tried to use the fact that for every compact surface there exists a finite cover $\{A_i\}_{i=1}^m$ such that the finite intersections of $A_i$'s are contractile.Let $\{A_i\}_{i=1}^m$ such cover for $M$.Then,using induction on $m$, we have :  -For $m=0$, $M$ is contractile and $G$ finitely generated then $H_r(M,G) $is finitely generated.  -For $m=r$ it's true by induction hypothesis.  -For $m=r+1$ now putting $A_{r+1}=B$ and $\cup_{i=1}^r A_i=A$, and using Mayer Vietoris we get:  $$ ...\rightarrow H_{r+1}(A\cap B,G)\rightarrow  H_{r+1}(A,G) \oplus H_{r+1}(B,G) \rightarrow H_{r+1}(M,G)\rightarrow H_{r}(A\cap B,G) \rightarrow...$$   Here I don't know what to do, maybe I'm missing some algebraic argument It's easy to see that $H_{r+1}(A\cap B,G)$ and $H_{r+1}(A,G) \oplus H_{r+1}(B,G)$ are finitely generated.But how can I argue that $H_{r+1}(M,G)$ is finitely generated? Any idea would be aprecciated. How to download and use any other kernel than the one which is installed by default Counting number of vertices of polygons and lines in QGIS? In QGIS, is there a way to count the number of vertices of polygons and lines in a given layer, and create a separate field containing these values?   I suspect it's a function somewhere in the field calculator but I can't find it. Is it normal for a fast prime to exhibit purple fringing in middle of the image? I have just bought a Nikon 50mm f/1.8D prime lens.  I took this picture (leg of my glasses frame on a mouse, and a LED desk lamp is on top of it) : f1.8, 1/80s, ISO 200   The purple fringing is right in the middle of the picture. Does it happen very often to this lens? Do photons bend spacetime or not? I have read this question:     where Safesphere says in a comment:     Actually, photons themselves don't bend spacetime. Intuitively, this is because photons can't emit gravitons, because, as any massless particles not experiencing time, photons can't decay by emitting anything. The latest theoretical results show that the gravitational field of a photon is not static, but a gravitational wave emanating from the events of the emission and absorption of the photon. Thus the spacetime is bent by the charged particles emitting or absorbing photons, but not by the photons themselves.        where John Rennie says:     as far as I know there has been no experimental evidence that light curves spacetime. We know that if GR is correct it must do, and all the experiments we've done have (so far) confirmed the predictions made by GR, so it seems very likely that light does indeed curve spacetime.   Now this cannot be right. One of them says photons do bend spacetime, since they do have stress-energy, but it is hard to measure it since the energy they carry is little compared to astronomical body's stress-energy. So they do bend spacetime, it is just that it is hard to measure it with our currently available devices.  Now the other one says that photons do not bend spacetime at all. It is only the emitting charge (fermion) that bends spacetime.  Which one is right? Do photons bend spacetime themselves because they do have stress-energy or do they not? What's the right terminology for Unity's UI elements? I've sent a few mails to the Ayatana mailing list regarding some UI suggestions for Unity, but I'm afraid I keep confusing the right terms for the UI element, so I would like to have some clarification.  Answer Index: Should I include a link to my Stack Overflow profile on my résumé? Using equations to draw out complex objects How do people come up with equations of curves to draw out complex objects?  Some popular examples would include:  &amp;  .  This  explains the rationale for the batman curve nicely.  But other than trial and error, I can't see a reasonable way of drawing the much more complicated PSY curve. Can I install any iOS version I wish by picking and choosing which firmware to restore? I'm trying to downgrade my iPhone from the current iOS to an older one, as per .  But every time I try, I always receive this error:     The iPhone could not be restored. This device isn't eligible for the requested build.     I have tried many times with and without DFU mode. Any ideas regarding this? Headers Including Each Other in C++ I'm a C++ newbie, but I wasn't able to find the answer to this (most likely trivial) question online.  I am having some trouble compiling some code where two classes include each other.  To begin, should my #include statements go inside or outside of my macros?  In practice, this hasn't seemed to matter.  However, in this particular case, I am having trouble.  Putting the #include statements outside of the macros causes the compiler to recurse and gives me "#include nested too deeply" errors.  This seems to makes sense to me since neither class has been fully defined before #include has been invoked.  However, strangely, when I try to put them inside, I am unable to declare a type of one of the classes, for it is not recognized.  Here is, in essence, what I'm trying to compile:  A.h  #ifndef A_H_ #define A_H_  #include "B.h"  class A {     private:         B b;      public:         A() : b(*this) {} };  #endif /*A_H_*/   B.h  #ifndef B_H_ #define B_H_  #include "A.h"  class B {     private:             A&amp; a;      public:         B(A&amp; a) : a(a) {}  };  #endif /*B_H_*/   main.cpp  #include "A.h"  int main() {     A a; }   If it makes a difference, I am using g++ 4.3.2.  And just to be clear, in general, where should #include statements go?  I have always seen them go outside of the macros, but the scenario I described clearly seems to break this principle.  Thanks to any helpers in advance!  Please allow me to clarify my intent if I have made any silly mistakes! How to use grep/awk/unix to match all lines from one file in another file, even if they are duplicates I'm trying to retrieve the the matching lines from a file, however the file that has the "index" or list of matches to retrieve also has duplicate entries and I want to print out the duplicates as well.  Example:  File 1 (index file or list of strings to match)  abc tgf abc ggg aaa fff   File 2 (what I want to retrieve for each of the matches in file 1)  Fred   1   3   abc Amy    2   4   ggg Dan    5   6   tgf Mike   9   1   fff Steve  2   1   aaa   My desired result would be (order is not important, just that I match every line):  Fred   1   3   abc Dan    5   6   tgf Fred   1   3   abc Amy    2   4   ggg Steve  2   1   aaa Mike   9   1   fff   I'm familiar and have tried grep as follows, but it does not print the duplicate entries.  grep -Fwf file1.txt file2.txt  Fred   1   3   abc Amy    2   4   ggg Dan    5   6   tgf Mike   9   1   fff Steve  2   1   aaa I have a txt file which actually is a html source of some webpage. Inside that txt file there are various strings preceded by a "title=" tag.  e.g.   &lt;div id='UWTDivDomains_5_6_2_2'  title='Connectivity Framework'&gt;    I am interested in getting the text Connectivity Framework to be extraced and written to a separate file.  Like this, there are many such tags each having a different text after the title='some text here which i need to extract '  I want to extract all such instances of the text from the html source/txt file and write to a separate txt file. The text can contain lower case, upper case letters and number only. The length of each text string(in characters) will vary.  I am using PowerGrep for windows. Powergrep allows me to search a text file with regular expression inout. I tried using the search as        title='[a-zA-Z0-9]  It shows the correct matches, but it matches only first character of the string and writes only the first character of the text string matched to the second txt file, not all string.   I want all string to be matched and written to the second file.  What is the correct regular expression or way to do what i want to do, using powergrep?  -AD. Why are mathematical proofs that rely on computers controversial? There are many theorems in mathematics that have been proved with the assistance of computers, take the famous  for example. Such proofs are often controversial among some mathematicians. Why is it so?  I my opinion, shifting from manual proofs to computer-assisted proofs is a giant leap forward for mathematics. Other fields of science rely on it heavily. Physics experiments are simulated in computers. Chemical reactions are simulated in supercomputers. Even evolution can be simulated in an advanced enough computer. All of this can help us understand these phenomena better.   But why are mathematicians so reluctant? replace internal memory Is it possible to replace internal memory of a android phone ?  How difficult it is?  Is internal memory part of System On Chip itself, so that it is next to impossible to remove them ?  Have anybody tried this out ?  My device is "Redmi Note" - but you can consider this as a generic question. If these is any device where replacing internal memory is  possible, I will switch to that device :)  Thanks