dlv hugo just hangs - go

I am trying to learn Hugo using a Go debugger called dlv. And I am pretty stuck. After:
go get -v github.com/gohugoio/hugo
cd $GOPATH/src/github.com/gohugoio/hugo
go build -gcflags="-N -l"
dlv exec ./hugo -- -s /path/to/the/projectdir
This hangs. Pressing Ctrl+C runs hugo as normal. As far as I can see dlv debug not only produces the same behavior but it's the exact same: the produced binary called debug is the exact same as the hugo I built with go build -gcflags="-N -l".
dlv launches a number of child processes, these disappear after a while. The hugo process is visible via ps and pidof hugo but strace -ppidof hugo`` reports strace: attach: ptrace(PTRACE_ATTACH, ...): No such proce. Checking after, it's still in the ps list, the same pid. I would guess because it's in t state as it is being traced.
How could I then watch Hugo running?

Aaaaand it's Linux subsystem for Windows! I never thought that'd make a difference but following Jonah B's answer " I am on fedora" I tried it on a Debian box and it worked. I am surprised because strace works fine on WSL (actually the github instructions on filing a report includes strace). I filed this bug.

Hmm, doesn't happen for me. dlv prompt appears right away. I am on fedora, have been using hugo regularly over the past week or so.
$ dlv exec ./hugo -- --cleanDestinationDir -s /path/to/blog/root/
Type 'help' for list of commands.
(dlv) c
| EN
+------------------+----+
Pages | 25
Paginator pages | 0
Non-page files | 0
Static files | 11
Processed images | 0
Aliases | 0
Sitemaps | 1
Cleaned | 0
Total in 46 ms
Process 41032 has exited with status 0
$

Same experience here. However it doesn't hang, it just takes a significant time to reach the dlv prompt.
Check the usage of your memory (for instance with mpstat or vmstat if you are on Linux). I have 16G main mem and 16G of swap. Until the dlv prompt is reached, nearly all my memory and a significant amount of swap is consumed. During the startup time any playing video or music stutters and the PC is practically unusable until dlv is ready.
Hugo is pretty large app in that respect.

Related

How to auto start script on boot on Raspbian OS Buster? [duplicate]

I now this has been asked before, but I have spent hours and hours trying to find out how to do this and absolutely nothing has worked. I have a python file that I want to automatically run in a terminal window after the pi has booted and loaded its GUI.
I don't know what else to do, and the annoying thing is I had it working for the same project (it took a long time to find out how then as well), but the pi crashed today and I can't remember how to do it again. All I can remember is that I added something to a file ending in /autostart, if that helps.
I was able to launch a python file on startup by running sudo nano /home/pi/.config/lxsession/LXDE-pi/autostart and adding #lxterminal -e python /home/pi/weatherStation/core.py at the end of the file
I had similar issues remembering where and how to do this. Then it all seemed to change again with Buster.
Having just freshly installed Buster onto a new SD card, I had to go through the whole process again. It's definitely easier the third or fourth time ;-)
I found that there was no lxsession folder in the path I had used before:
/home/pi/.config/lxsession/LXDE-pi/autostart
/home/pi/.config/lxsession did not exist in the Buster I just installed (May 2020)
I found a 2020 Buster related article here:
http://wideberry.com/autostart-python-script-after-boot-in-raspbian-buster/
and from that found the autostart file in this path:
/etc/xdg/lxsession/LXDE-pi
Note: this is a root file and will affect all users.
As I had previously found an issue with timings of when to issue the python command, I call a script to pause before running my python scripts.
I added an #lxterminal command in my /etc/xdg/lxsession/LXDE-pi/autostart as follows:
lxpanel --profile LXDE-pi
#pcmanfm --desktop --profile LXDE-pi
#lxterminal -e /home/pi/StartCollectors.sh
#xscreensaver -no-splash
Note: as /etc/xdg/lxsession/LXDE-pi/autostart this is a root protected file, it had to be edited with root powers, e.g. sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
StartCollectors.sh contains this
#!/bin/bash
# started from the /etc/xdg/LXDE-pi/autostart file (reminder)
cd /home/pi/ETA2-copy
echo "starting House Collectors in 20 seconds"
sleep 10
echo "starting House Collectors in 10 seconds"
sleep 10
lxterminal --working-directory='/home/pi/ETA2-copy' --command='python3 Hiverun.py' -t 'Hive'
lxterminal --working-directory='/home/pi/ETA2-copy' --command='python3 ETALog.py' -t 'ETA'
lxterminal --working-directory='/home/pi/ETA2-copy' --command='python3 ETADailySum.py' -t 'Summary'
echo "My work is done. Closing in 10 seconds
sleep 10
exit
the -t options put a recognizable name on the terminal window.
It works.
BTW I collect data from an ETA PU15 boiler over my local Lan. I collect data from my British Gas Hive home control system and the UK Met Office and integrate it into an sqlite table so that I can track the house performance. Why? Why not? Call it a hobby.
I think this is my first answer on this forum. I hope it conforms and that it helps others.

Is there a way to see how much time remains on a timed process?

Is there a way to determine (in bash) how much time is remaining on a process that is running for a specified time?
For example, some time after executing
caffeinate -s -t 8000 &
is there a command or technique for determining when my system will be allowed to sleep?
Bash won't know that caffeinate has a timer attached to it; for all it knows, -t refers to the number of times you'll place an Amazon order of Red Bull before the process exits five minutes later.
If you know this, however, you can detect when the command was started and do the math yourself.
$ sleep 45 &
[1] 16065
$ ps -o cmd,etime
CMD ELAPSED
sleep 45 00:03
ps -o cmd,etime 00:00
/bin/bash 6-21:11:11
On OS X, this will be ps -o command,etime; see the FreeBSD ps man page or Linux ps docs for details and other switches/options.

Attach to and debug an already running Ruby script on Linux?

I'm on Linux with a Ruby script running in a terminal window (it sits in a while loop with some sleep timeout, and does work when something changes.)
The problem is, occasionally the script seems to freeze and stop responding. A typical scenario is if I leave it sitting overnight.
If I break and restart it, the script works fine.
So, 1) is there a way to attach to this already-running ruby script's interpreter to find out where it's getting stuck? Ideally I'd get a stack trace.
If not possible on-the-fly, 2) how can I run it so that next time it freezes I can get a stack?
I think there are likely better "ruby ways" to solve this problem. But doing a google search on attach to a running ruby process turned up a blog post with some helpful suggestions for using gdb to debug a live Ruby process on Linux: Tools for Debugging Running Ruby Processes. This further linked to another blog post with some useful information on using gdb to get a ruby stack trace:
Find the PID of your ruby script, e.g.
ps aux | grep -i <script_name.rb>
Attach to it with gdb:
sudo gdb `which ruby` <pid>
Run these commands in gdb to get the Ruby backtrace:
(gdb) set $ary = (int)backtrace(-1)
(gdb) set $count = *($ary+8)
(gdb) set $index = 0
(gdb) while $index < $count
> x/1s *((int)rb_ary_entry($ary, $index)+12)
> set $index = $index + 1
>end
This got me close, but gdb encountered an error while loading ruby symbols, and another error trying to run the backtrace function. I'll update this answer as I figure out more. Feel free to make other suggestions.
The blogpost also links an interesting set of gdb recipes for debugging Ruby.

How to examine processes in OS X's Terminal?

I’d like to view information for processes running in OS X. Running ps in the terminal just lists the open Terminal windows. How can I see all processes that are running?
Say I’m running a web browser, terminal and text editor. I’d like to see information for the text editor and web browser.
Running ps -e does the trick. Found the answer here.
You can just use top
It will display everything running on your OSX
Using top and ps is okay, but I find that using htop is far better & clearer than the standard tools Mac OS X uses. My fave use is to hit the T key while it is running to view processes in tree view (see screenshot). Shows you what processes are co-dependent on other processes.
You can install it from Homebrew using:
brew install htop
And if you have Xcode and related tools such as git installed on your system and you want to install the latest development code from the official source repository—just follow these steps.
First clone the source code from the htop GitHub repository:
git clone git#github.com:hishamhm/htop.git
Now go into the repository directory:
cd htop
Run autogen.sh:
./autogen.sh
Run this configure command:
./configure
Once the configure process completes, run make:
make
Finally install it by running sudo make install:
sudo make install
Try ps -ef. man ps will give you all the options.
-A Display information about other users' processes, including those without controlling terminals.
-e Identical to -A.
-f Display the uid, pid, parent pid, recent CPU usage, process start time, controlling tty, elapsed CPU usage, and the associated command. If the -u option is also used, display
the user name rather then the numeric uid. When -o or -O is used to add to the display following -f, the command field is not truncated as severely as it is in other formats.
Try the top command. It's an interactive command that will display the running processes.
You may also use the Apple's "Activity Monitor" application (located in /Applications/Utilities/).
It provides an actually quite nice GUI. You can see all the running processes, filter them by users, get extended informations about them (CPU, memory, network, etc), monitor them, etc...
Probably your best choice, unless you want to stick with the terminal (in such a case, read the top or ps manual, as those commands have a bunch of options).
To sort by cpu usage: top -o cpu
if you are using ps, you can check the manual
man ps
there is a list of keywords allowing you to build what you need. for example to show, userid / processid / percent cpu / percent memory / work queue / command :
ps -e -o "uid pid pcpu pmem wq comm"
-e is similar to -A (all inclusive; your processes and others), and -o is to force a format.
if you are looking for a specific uid, you can chain it using awk or grep such as :
ps -e -o "uid pid pcpu pmem wq comm" | grep 501
this should (almost) show only for userid 501. try it.
The slightly GUI way
if you are a cli (ui) fan. I recommend trying https://github.com/clementtsang/bottom which shows not only processes, but also temperature, disk usage and network. Screenshot is running from kitty (terminal) as an example, I use it on OSX default terminal and the color shows up a bit different, but still amazing.
The tree way
As described here : https://en.wikipedia.org/wiki/Pstree will give a better connection on the hierarchy of the processes
brew install pstree # if you need to install it
pstree
pstree -u <user> # show only processes by your user
pstree -s <string> # show only processes with string
pstree -help # show help

AWT-Shutdown and AWT-EventQueue do not terminate after plotting a 2D graph with JFreeChart

I am trying to do something really basic;
Plot an array of integers as time-series data using JFreeChart. Previously the code was working perfectly fine. That is the point that drives me crazy.
However, now it fails to terminate after doing everything it is supposed to do. Active threads are as follows;
Thread[AWT-Shutdown,5,main]
Thread[AWT-EventQueue-0,6,main]
Thread[main,5,main]
I am using a Macbook with Mac OS 10.6.8 on it, and got a set of recent software updates.
Does anybody have any clue about where to start, and what to look for?
You can get more infomation from the terminal:
Launch your program in the background
$ java -jar dist/program.jar &
Get its process id
$ ps
PID TTY TIME CMD
714 ttys000 0:00.01 -bash
727 ttys000 0:01.52 /usr/bin/java -jar dist/program.jar
Obtain a thread dump
$ kill -QUIT 727
Look for anything not in State: WAITING or State: RUNNABLE
Your IDE's profiler may offer a more friendly view of the same information. See also JLS §12.8 Program Exit. An sscce may help, too.

Resources