-1

Is it possible to forbid creation of coredumps only for my program? I know that it's possible to change behaviour for entire system using ulimit, but I'd like to block it only for my program. What should I code in my program? Maybe write some kernel module?

Ivan Kush
  • 2,958
  • 2
  • 23
  • 39
  • 1
    I don't see the point of doing this. Whether core dumps should be allowed is a policy question that should be decided by the user running the program and / or by the system administrator. Programs generally ought not to try to take such things into their own hands. – John Bollinger May 15 '20 at 19:56
  • 1
    In following @JohnBollinger's comment, one could create a no-dump user (or group), chown that binary to be owned by that user, and set the SUID bit on it so the program runs as said user, and restrict core-dumps for that user in limits.conf. That way it is something configurable by the system administrator. – Christian Gibbons May 15 '20 at 20:02

1 Answers1

2

Call setrlimit() to do the same thing that the ulimit command does.

#include <sys/resource.h>

struct rlimit new;
new.rlim_cur = new.rlim_max = 0;
setrlimit(RLIMIT_CORE, &new);
Barmar
  • 741,623
  • 53
  • 500
  • 612