2

I have 9 different bash processes running at all times (I sometimes get more, for example, I have 37 bash processes now.). I found this question, where OP had a similar issue. But I don't see this as a duplicate (because that asks how to debug, my question is directly why) I ran this lsof | grep 'bash.*cwd' and see that they were all in ~ except one which was in /private/tmp.

The answer says I should use pstree, which I don't have and then it says I should use ps aux -H, however, I have BSD ps, where -H is an "illegal operation". So I installed pstree and ran pstree, and this was my output

  -+= 00001 root /sbin/launchd
 |-+= 67440 root login -pf avnamn
 | | \--= 96033 avnamn -bash
 | | \--= 99021 avnamn -bash
 |   \-+= 99355 avnamn -bash
 |     \--- 99491 avnamn grep bash
 | \-+- 67441 avnamn -bash
 |   \--- 69408 avnamn -bash
 | \-+- 08457 avnamn -bash
 |   \--- 08513 avnamn -bash
 | \-+- 19936 avnamn -bash
 |   \--- 20053 avnamn -bash
 |-+= 90217 root login -pfl avnamn /bin/bash -c exec -la bash /bin/bash
 | \--- 90218 avnamn -bash
   \--- 20873 avnamn -bash

avnamn is my username. I removed things that were not part of that branch. This does not tell me much, and unlike OP in the other question, this does not go away when I restart. It's annoying because it makes my fans very loud, I can kill the processes but they come back after a while.

ps aux output, with the one that uses a lot of CPU.

avnamn          34737  51,4  0,0  2476312   4832 s000  R+    1:49am  14:14.28 -bash

top output, with the one that uses a lot of CPU.

34737  bash             0.0  15:02.72 1/1   0   17+    4056K+ 0B     0B     34736 34736 running  *0[1+]      0.00000 0.00000    501 1959+     367+    182+        33+        4456+     213005750+ 215920747+  0       0        0.0   avnamn          N/A    N/A   N/A   N/A   N/A   N/A  

Output of ps -ef | awk ' NR == 1 { header = $0; next } { pid[$2] = $0 } /bash/ { toprint[$2] } END { print header; for (i in toprint) { while (i != 1) { split(pid[i], pieces, " "); i = pieces[3]; toprint[i] } } for (i in toprint) { print pid[i] } }':

   0 54267     1   0 11:29pm ttys011    0:01.06 login -pf avnnamn
 501 61203 61158   0  6:57pm ttys007    0:00.00 -bash
 501 52955 52582   0 11:22pm ttys010    0:00.00 -bash
   0 54462     1   0  6:22pm ttys003    0:00.02 login -pf avnnamn
   0 61157     1   0  6:57pm ttys007    0:00.02 login -pf avnnamn
   0 15864     1   0  3:02pm ttys005    0:00.02 login -pf avnnamn
 501  8378  8377   0 11:39pm ttys012    3:39.31 -bash
 501  9716     1   0 11:47pm ??         0:00.39 /Applications/Utilities/Terminal.app/Contents/MacOS/Terminal
   0 52581     1   0 11:20pm ttys010    0:01.07 login -pf avnnamn
   0  8495     1   0 11:40pm ttys013    0:01.04 login -pf avnnamn
   0 71228     1   0  7:46pm ttys009    0:00.02 login -pf avnnamn
 501 54268 54267   0 11:29pm ttys011    0:00.03 -bash
 501  9751  9720   0 11:47pm ttys015    0:00.02 -bash
   0  9720  9716   0 11:47pm ttys015    0:01.15 login -pf avnnamn
 501  8496  8495   0 11:40pm ttys013    0:00.02 -bash
 501  8515  8496   0 11:40pm ttys013    0:00.00 -bash
 501 61158 61157   0  6:57pm ttys007    0:00.04 -bash
 501 71229 71228   0  7:46pm ttys009    0:00.08 -bash
   0 59136     1   0  6:46pm ttys004    0:00.03 login -pf avnnamn
   0 59962     1   0  6:50pm ttys006    0:00.02 login -pf avnnamn
 501 52582 52581   0 11:20pm ttys010    0:00.03 -bash
   0  3066     1   0  3:04am ttys000    0:00.13 login -pf avnnamn
 501 55004 54268   0 11:34pm ttys011    0:00.00 -bash
 501 73098 71229   0  7:55pm ttys009    0:00.00 -bash
   0  8377     1   0 11:39pm ttys012    0:01.04 login -pf avnnamn
 501 71202 71201   0  7:46pm ttys008    4:18.90 -bash
   0 28465     1   0 10:52pm ttys001    0:00.01 login -pf avnnamn
   0     1     0   0  2:53am ??         4:12.90 /sbin/launchd
 501  3067  3066   0  3:04am ttys000    0:00.05 -bash
 501  3152  3067   0  3:05am ttys000    0:00.00 -bash
 501  7043  7042   0  3:27am ttys002    0:00.02 -bash
 501  7048  7043   0  3:27am ttys002    0:00.00 -bash
 501 15865 15864   0  3:02pm ttys005    0:00.03 -bash
 501 16395 15865   0  3:05pm ttys005    0:00.00 -bash
 501 28466 28465   0 10:52pm ttys001    0:00.04 -bash
 501 28853 28466   0 10:55pm ttys001    0:00.00 -bash
 501 54463 54462   0  6:22pm ttys003    0:00.05 -bash
 501 54901 54463   0  6:24pm ttys003    0:00.00 -bash
 501 59137 59136   0  6:46pm ttys004    0:00.04 -bash
 501 59142 59137   0  6:46pm ttys004    0:00.00 -bash
 501 59963 59962   0  6:50pm ttys006    0:00.09 -bash
 501 61156 59963   0  6:57pm ttys006    0:00.00 -bash
9
  • 3
    pstree outputs a tree. Using grep on that makes no sense. Find your "bad" bash and go up the tree to see who spawns that bash. Also have a look at ps uxf.
    – michas
    Dec 10 '15 at 21:46
  • This pstree-surrogate doesn't reveal much. How about ps l -U avnamn or a full ps waxl?
    – ott--
    Dec 10 '15 at 21:49
  • @michas, sorry, fixed now. Dec 10 '15 at 21:55
  • Does ps uxf work on your system? Does crontab -l list any entries?
    – michas
    Dec 10 '15 at 22:02
  • 2
    Any number of things could cause that, it depends on what your shell's startup files are doing. Please edit your question and show us the relevant line of ps aux output for that bash process. Ideally, also show it from top. We need to figure out what that process is doing and we can't do that from the information you've given us. For example, once you have the process's PID, you can get its parent PID with ps -p ProcessPID -o ppid and then see what's launching it.
    – terdon
    Dec 10 '15 at 23:29
0

If a shell process is running a lot consuming CPU, to me you need to see if it a login shell or something running a shell script. You seem to have a lot of login processes, do you normally login 9 times on different ttys?

pstree may help in finding, say, a misbehaving parent. For example I've seen ppp daemons spawn "bad" shells that immediately exit and it keeps restarting over and over.

However, you have a shell consuming lots of CPU. This implies a shell script that is going wrong. The trick is working out what these scripts are. On bash in Linux, its simple, ls -l /proc//fd/10 will most likely tell you the script name. I'm not sure if bsd has this feature.

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.