[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: getting a regular user to dump core when a program crashes



On Mon, Feb 28, 2022 at 11:25:13AM -0500, songbird wrote:
> >> me@ant(14)~$ ulimit -a
> >> real-time non-blocking time  (microseconds, -R) unlimited
> >> core file size              (blocks, -c) unlimited
> 
>   i had accomplished the ulimit change already, but the lack of 
> the proper permission on the output directory meant that a core
> file would not be generated.

What is an "output directory"?  Core files are dumped in the process's
*working* directory, which is "where you are when you run it".  Quite
often that will be $HOME, unless you opened a shell and changed
directory somewhere else, before running a command.  Or unless the
process is invoked by a dot-desktop file that specifies a special
working directory.  Or a systemd unit file is written which specifies
a WorkingDirectory= in it.  And so on.

unicorn:~$ cat coredump.c
main() {
    char *ptr = 0;
    *ptr = 'x';
    return 0;
}
unicorn:~$ gcc -o coredump coredump.c
coredump.c:1:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
    1 | main() {
      | ^~~~
unicorn:~$ cd tmp
unicorn:~/tmp$ ../coredump >/var/tmp/outputfile
Segmentation fault (core dumped)
unicorn:~/tmp$ ls -ld core
-rw------- 1 greg greg 249856 Feb 28 11:33 core

Here, the process's binary file lives in /home/greg, its working directory
is /home/greg/tmp, and its stdout has been redirected to a file in
/var/tmp.  The core file goes in /home/greg/tmp, the working directory.


Reply to: