g++ main.cpp -g -o process
- -g : adds debugging information to executable, aiding debugging process with tools like GDB
ulimit -c unlimited
- ulimit -c unlimited sets core file size limit to unlimited, allowing creation of core dumps.
sudo sysctl -w kernel.core_pattern=./core.%e.%p.%t
- sets core dump filename pattern to include process name, PID, and timestamp.
2- Lets Go with the first task to check the CPU load for the system, after running the process software
-
Actully We Could Use
$ top
-
But I just Found
$ htop
with fancy GUI
- I also found that
$ ps
got some nice argu
ps -C process -o %cpu
-C
: allows you to use process name without knowing it's pid.-o %cpu
: Specifies the output format to display only the CPU
$ ps -eo pcpu,pid,user,args | sort -k 1 -r | head -3
- You can also use the ps command to view the top 2 most CPU-intensive processes
$ top -b -n 2 -d 0.2 -p 6962 | tail -1 | awk '{print $9}'
> 100.0 # yup that's simple D:
b
: Batch-mode non-interactive mode, suitable for scripts.-n 2
: Number-of-iterations, use 2 because: When you first run it, it has no previous sample to compare to, so these initial values are the percentages since boot.d 0.2
: Delay-time(in second, here is 200ms)p 6962
: Monitor-PIDstail -1
: the last rowawk '{print $9}'
: the 9-th column(the cpu usage number)
- To get the core-dump file we should
$ kill
the process with signalSIGQUIT
as it requests controlled termination with core dump, aiding debugging by capturing program state.
kill -QUIT <PID>
- Now we got :
Hello from process
Hello from process
Hello from process
Hello from process
Quit (core dumped)
-
And finally, I got core-dump file
core.process.10902.
-
Lets Open
gdb
and where the process terminated:
$ gdb ./process core.process.10902.
GNU gdb (Ubuntu 9.2-0ubuntu1~20.04.1) 9.2
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./process...
[New LWP 10902]
Core was generated by `./process'.
Program terminated with signal SIGQUIT, Quit.
#0 0x000055fdbe05b262 in loadCPU () at main.cpp:17
warning: Source file is more recent than executable.
17 void loadCPU() {
(gdb)
- And yes we got
Program terminated with signal SIGQUIT, Quit #0 0x000055fdbe05b262 in loadCPU () at main.cpp:17
- to Assign Priority at runtime
$ renice
- to Assign Priority before runtime
$ nice
Execute a program with a custom scheduling priority (niceness).Niceness values range from -20 (the highest priority) to 19 (the lowest).
- Launch a program with altered priority:
nice -n {{niceness_value}} {{command}}
nice -n -10
dd if=/dev/zero of=/dev/null