2022年12月20日 星期二

Generate Core Dump File C++ on Ubuntu 20.04



setup

cat /proc/sys/kernel/core_pattern
|/usr/share/apport/apport -p%p -s%s -c%c -d%d -P%P -u%u -g%g -- %E
$ ulimit -c
0
$ ulimit -c unlimited
0
$ ulimit -c
unlimited

setup
sudo sysctl kernel.core_pattern=/var/crash/core.%c.%d.%p.%t.%s.%E
cat /proc/sys/kernel/core_pattern
/var/crash/%E.%p.%t.%s

code

touch a.cpp
nano

int main() {
int a = 1/0;
int b = a+1;
return 0;
}

g++ a.cpp
./a.out
Floating point exception (core dumped)

dump

ll /var/crash/
core.18446744073709551615.1.30876.1671522014.8.!home!user!a.out

 

No use

ll /var/lib/apport/coredump
sudo sysctl kernel.core_pattern=core.%p.%s.%c.%d.%P

Reference

https://askubuntu.com/questions/440708/unable-to-generate-core-dump-after-apport-disable

2022年12月16日 星期五

docker with postgres:14.3

https://medium.com/alberthg-docker-notes/docker%E7%AD%86%E8%A8%98-%E9%80%B2%E5%85%A5container-%E5%BB%BA%E7%AB%8B%E4%B8%A6%E6%93%8D%E4%BD%9C-postgresql-container-d221ba39aaec

docker pull postgres:14.3
docker create --name my-postgres -p 8080:5432 -e POSTGRES_PASSWORD=admin postgres:14.3
docker start my-postgres


docker exec my-postgres psql --help
docker exec my-postgres psql -V
docker exec my-postgres psql -U postgres -l
docker exec -it my-postgres psql -U postgres
\q


docker exec -it my-postgres bash
apt-getupdate
apt-get install net-tools
172.17.0.2

docker exec -it my-postgres psql -U postgres -c "create role <user-name> with login password '<password>';"

docker from scratch

 https://www.runoob.com/docker/docker-container-usage.html

Windows 11, Install docker Desktop, choose WSL2 not HyperV

docker run -itd -P --name banana ubuntu /bin/bash  # -d detached, -P all ports
docker exec -it banana ubuntu /bin/bash  # interactive, terminal
apt-get install curl  # this may cause Unable to locate package curl
apt-get update # then can install
apt-get install curl
apt-get install ssh
service ssh start
systemctl enable enable ssh
service ssh status
apt-get install net-tools
apt-get install netcat
apt-get install iputils-ping
ping 172.17.0.1  # this is the host
apt-get install telnet
telnet 172.17.0.1 8000

docker ps -a  # active

docker stop banana
docker commit banana banana02
docker run -itd -p 5432:5000 --name banana02 banana02 /bin/bash
docker exec -it banana02 /bin/bash
python3 -m http.server 5000
On host, firefox http://127.0.0.1:5432
On banana02, see 172.17.0.1 GET / 200

docker images

1、从已经创建的容器中更新镜像,并且提交这个镜像 (commit)

docker run -itd --name banana02 ubuntu:22.04 /bin/bash
docker exec -it banana02 /bin/bash
apt-get update
apt-get install -y iputils-ping netcat telnet
docker commit -m="John first commit" -a="John Doe author" banana02 ubuntu:v1
docker run -itd -P --name banana03 ubuntu:v1 /bin/bash
docker exec -it banana03 /bin/bash
nc -l 5000
On host, telnet 127.0.0.1 49154

2、使用 Dockerfile 指令来创建一个新的镜像 (Dockerfile)

cat Dockerfile
FROM    ubuntu:22.04
MAINTAINER      Fisher "fisher@sudops.com"
RUN     apt-get -y update
RUN     apt-get install -y iputils-ping netcat telnet
EXPOSE  22
EXPOSE  80
EXPOSE  5000

docker build -t ubuntu:v2 .
docker run -itd -p 5000:5000 -P --name banana04 ubuntu:v2 /bin/bash
docker exec -it banana04 /bin/bash
49159:22
5000:5000
49158:80
docker tag ubuntu:v2 ubuntu:v3





End






2022年12月1日 星期四

GDB with a crash file and usual commands (and also CLion)

The crash file could be just 10MB


Commands

sudo apport-unpack some.10MB.crash CoreDump

sudo chown -R user:user CoreDump/

cd ./CoreDump

gdb ./binary CoreDump


Commands

frame

up

down

bt

list

info locals

info args

print iter

print hashTable


CLion

Run > Open Core Dump

Core dump: The 200MB core dump file

Symbol file: The originating executable file

2007 to 2023 HP and Dell Servers Comparison

  HP Gen5 to Gen11  using ChatGPT HP ProLiant Gen Active Years CPU Socket Popular HP CPUs Cores Base Clock Max RAM Capacity Comparable Dell ...