Why kill command does not generate core while gcore can? - linux

I can use gcore generating the core file of my application which was built with debug symbol. Out of curiosity, I tried using kill command to generated the core file, but no core is generated.
Here are the steps I took:
I first ran the following commands:
ulimit -c unlimited
sudo sysctl -w kernel.core_pattern=/tmp/core-%e.%p.%h.%t
Then start the application.
Then I tried the SIGABRT, SIGTRAP, SIGQUIT, there is no core file generated:
kill -SIGABRT `pidof my_app`
kill -SIGTRAP `pidof my_app`
kill -SIGQUIT `pidof my_app`
In all these runs, my_app was stoped, but there is no core file, locally or /tmp.
I am using Ubuntu 20.04.
Do you see anything wrong?

Related

how to run process from batch script

I have simple batch script in linux debian - Debian GNU/Linux 6.0 - that stop process then deletes log files and start the process again :
#!/bin/bash
killall -KILL rsyslogd
sleep 5s
rm /var/log/syslog
rm /var/log/messages
rm /var/log/kern.log
sleep 3s
rsyslogd
exit
The process name is rsyslogd. I have to close it before deleting the log files, for linux to empty the space from disk.
I see that killall -KILL closes the process by its name, but what is the opposite - the run command?
Calling it by its name without any command seems to not work. I will be glad for any tips, thank you.
Debian uses systemd to manage processes. You should, therefore, use the systemd's commands to stop and start rsyslogd.
systemctl stop rsyslog
and
systemctl start rsyslog
If you are using really old versions of Debian (so old that you should upgrade), it may be possible that sys V is still used. In that case, there is a file under /etc/init.d which is called rc.rsyslog or something comparable (use ls /etc/init.d to find the exact name). In that case, it would be
sudo /etc/init.d/rc.rsyslog stop
and
sudo /etc/init.d/rc.rsyslog start
Or it may be, that your systemd-package may be broken. In that case, the package can be re-installed:
apt-get --reinstall install systemd
To start rsyslogd:
systemctl start rsyslog
To stop it:
systemctl stop rsyslog
If you want to do both, use
systemctl restart rsyslog

get the core file in perl script with backtick

On my ubuntu 14.04 (Linux 3.19.0 64bit) PC, I ran a perl program that has the following in a loop
$params = setupParams();
$ret = `SOME_CMD $params`;
...
But for some reason, SOME_CMD sometimes gaves Segmentation fault (core dumped) occasionally. In order to figure out the cause of the core dump, I need to get the core file.
Unfortunately I tried ulimit -S -c 0 on the terminal where I ran the perl script, but it didn't produce a core file.
Any ideas would be appreciated.
ulimit -c 0 prevents core files to be written. You need to use
ulimit -c unlimited
Btw: you should upgrade to a maintained OS.

How to stop the generation of strace.out files

I started the JBoss instance using the following command:
strace -o strace.out -ff ./startMethodServer.sh
Now i want to stop the generation of these strace.out files
How can i do this?
I have no clue about JBoss, but would advice to remove
-o strace.out
from invocation, since the the usual behaviour of many cli tools is to specify an output file with -o outputfile.
You'd have to stop the server and restart it without strace. The strace command has nothing to do with JBoss AS. It's part of the OS therefore it must be controlled by the OS.
The command
strace -o strace.out -ff ./startMethodServer.sh
is running the script ./startMethodServer.sh using strace. The strace program is writing the strace.out file, and will continue doing that until ./startMethodServer.sh exits. The only way to stop writing those files is to stop the strace process (which will stop ./startMethodServer.sh), and restart ./startMethodServer.sh without involving strace:
./startMethodServer.sh

crashed process but no core dump file

I have tried may things but I can get my program to generate core dump when it crashes.
$ ulimit -c
200000000
The limit seems ok.
$ cat /proc/sys/fs/suid_dumpable
2
The pattern looks ok.
$ cat /proc/sys/kernel/core_pattern
/tmp/core_%e
When I kill -SIGSEGV I get a core dump. The process has very little memory. Why is there no core dump file?
I have a print at the end of main that i don't see and I'm running the program in bash while loop with sleep 2;
The os is Ubuntu 12.04LTS

How to dump core of an init spawned process

I am trying to force core dump of a program. Core dumping is enabled via
ulimit -c unlimited
If my program is launched by the init process, and I kill it like this
kill -6 <pid_of_prog>
I can't find the core.
However, if it is launched from a terminal, and I kill it with the above command, then it dumps core. The program chdir to a directory when it is launched, and the core file is found in this directory.
ulimit does not set the limit of already launched process, so my init launched process is not affected by the ulimit command. I guess the correct answer is to use setrlimit

Resources