It's probably killed by kernel's oom killer. dmesg should contain information about it. Sorry, but you may need to redesign your algorithm.

Answer from rvs on Stack Exchange
🌐
Reddit
reddit.com › r/archlinux › c program stopped automatically - output "killed"
r/archlinux on Reddit: C program stopped automatically - output "Killed"
July 31, 2015 -

Hey guys, I'm running an ArchLinux on a Raspberry Pi and a BeagleBoard. I compiled a C program that does some calculations with various datatype. I had no problem with int and long so far, but with long long I encounter a problem:

The program is stopped automatically after some (longer) time and I get the output "Killed" on the terminal. Is there an auto-kill script running per default or something like this? What could've happend here?

Please help me (and ask more questions if you need them). Thanks

Edit: The solution:

You can change a value and disable the over-allocation of memory which was the problem in my case (at elast it works):

echo "2" > /proc/sys/vom/overcommit_memory

Source

🌐
Cprogramming
cboard.cprogramming.com › c-programming › 38203-killed-message.html
killed message
When I execute the program, I get an error message "killed" on the screen. Obviously the array is too big. How do I get C to handle extremely large arrays? THANKS, -Prof D ... Are you sure you need such a big array? And are you sure thats the exact number you need? Why dont you creat some variable/struct and just allocate the memory when needed so you dont over use memory, you only use what you need. Show us your code and we may give you other alternatives.
Discussions

linux - Program in C executed and the terminal shows: Finished (killed) - Stack Overflow
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 9 years ago. ... I was running a program in C from the terminal in Linux and I get the message "Finished (killed)". More on stackoverflow.com
🌐 stackoverflow.com
linux - Killing a process with C program - Stack Overflow
Do you know that there's a kill(2) ... you to kill a process without the need to call an external command? ... Save this answer. ... Show activity on this post. ... system(3) does NOT return PID of child process, but instead waits for it to exit, and returns its exit code... More on stackoverflow.com
🌐 stackoverflow.com
Coding Games and Programming Challenges to Code Better
CodinGame is a challenge-based training platform for programmers where you can play with the hottest programming topics. Solve games, code AI bots, learn from your peers, have fun. More on codingame.com
🌐 codingame.com
November 13, 2019
c++ - My program was "Killed" - Stack Overflow
Those functions are not forbidden but not recommended, as they can throw a new signal and your code will hang or behave in undefined way. Sometime we need to use the right words :-). In any case, you are probably running out of memory and the kernel is killing your program with a sigkill/sigterm. More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 2
3

You almost certainly lack a swap partition, or you have some other utility monitoring the amount of available free memory, and therefore your program is killed because it consumes too much memory, up to the point that there is no free ram left.

You can use htop or conky to have a clear view of the issue.


If instead you had a swap partition then your system would attempt to swap the memory from/to the disk, and this would most likely freeze it. This is a much worse scenario, because in most cases the only action that you can take to get the system back working is to reboot it: in my experience, when the system freezes then it no longer responds to any keyboard input.


On my system it takes 2m26s for your executable to fill over 50% of the available 8GB of RAM, not counting the additional 32% that is occupied by the other running programs.


You might want to use a memory leak profiling tool (e.g. valgrind) to check for potential leaks, or simply inspect the source code manually. If you can't reduce its memory footprint, then your only option is to look for a much more powerful machine with a larger pool of RAM.

2 of 2
2

Compile and link with debugging information using -g, then run the program under control of a debugger such as gdb and watch where it stops. You should see which line of source code causes the problem that gets your program killed by the system.

$ gcc -O2 -g -o my_program my_program.c
$ gdb my_program
gdb> run

If your program needs command line arguments, type them on the run command

gdb> run arg1 arg2
🌐
Al Jensen's Programming
aljensencprogramming.wordpress.com › 2014 › 05 › 15 › the-kill-function-in-c
The kill() Function in C | C Programming with Al Jensen
May 15, 2014 - The easiest way to send a signal to a process is via the kill() signal. #include #include #include #include int main(void){ pid_t r…
🌐
Linux Hint
linuxhint.com › kill-system-call-in-c
Kill() Function in C Language – Linux Hint
Once the two processes are running, ... As we can see, the receiving process is stopped with the SIGKILL signal: The kill() function is a system function that interacts with two or more processes....
🌐
CodinGame
codingame.com › forum › t › killed-on-c-memory-reservations › 140640
Coding Games and Programming Challenges to Code Better
November 13, 2019 - CodinGame is a challenge-based training platform for programmers where you can play with the hottest programming topics. Solve games, code AI bots, learn from your peers, have fun.
Find elsewhere
Top answer
1 of 2
6

In C++, a float is a single (32 bit) floating point number: http://en.wikipedia.org/wiki/Single-precision_floating-point_format

which means that you are allocating (without overhead) 3 840 000 000 bytes of data.

or roughly 3,57627869 gigabytes..

Lets safely assume that the header of the vector is nothing compared to the data, and continue with this number..

This is a huge amount of data to build up, Linux may assume that this is just a memoryleak, and protect it self by killing the application:

https://unix.stackexchange.com/questions/136291/will-linux-start-killing-my-processes-without-asking-me-if-memory-gets-short

I don't think this is an overcommit problem, since you are actually utillizing nearly half the memory in a single application.

but perhaps.. consider this just for fun.. are you building an 32bit application? you are getting close to the 2^32 (4Gb) memory space that can be addresssed by your program if it's a 32 bit build..

So in case you have another large vector allocated... bum bum bum

2 of 2
0

First install the signal handler for example

static bool installSignalHandler(int sigNumber, void (*handler)(int) = signal_handler)
{
    struct sigaction action;
    memset(&action, 0, sizeof(action));
    action.sa_flags = SA_SIGINFO;
    action.sa_sigaction = signal_handler_action;
    return !sigaction(sigNumber, &action, NULL);
}

Call it:

installSignalHandler(SIGINT);
installSignalHandler(SIGTERM);

And the next code will be executed:

static void signal_handler_action(int sig, siginfo_t *siginfo, void* content) 
{
    switch(sig) {
        case SIGHUP:
            break;
        case SIGUSR1:
            break;
        case SIGTERM:
            break;
        case SIGINT:
            break;
        case SIGPIPE:
            return;
    }
}

Take a look at the siginfo_t structure for the data you want

printf("Continue. Signo: %d - code: %d - value: %d - errno: %d - pid: %ld - uid: %ld - addr %p - status %d - band %d",
                      siginfo->si_signo, siginfo->si_code, siginfo->si_value, siginfo->si_errno, siginfo->si_pid, siginfo->si_uid, siginfo->si_addr,
                      siginfo->si_status, siginfo->si_band);
🌐
GNU
gnu.org › software › libc › manual › html_node › Kill-Example.html
Kill Example (The GNU C Library)
*/ volatile sig_atomic_t usr_interrupt ... */ printf ("I'm here!!! My pid is %d.\n", (int) getpid ()); /* Let parent know you’re done. */ kill (getppid (), SIGUSR1); /* Continue with execution....
🌐
GitHub
github.com › util-linux › util-linux › blob › master › misc-utils › kill.c
util-linux/misc-utils/kill.c at master · util-linux/util-linux
static int kill_with_timeout(const struct kill_control *ctl) { int pfd, n; struct pollfd p = { 0 }; siginfo_t info = { 0 }; struct list_head *entry; · info.si_code = SI_QUEUE; info.si_signo = ctl->numsig; info.si_uid = getuid(); info.si_pid = getpid(); info.si_value.sival_int = ctl->use_sigval != 0 ?
Author   util-linux
🌐
List of Deaths Wiki
listofdeaths.fandom.com › wiki › C.C._(Code_Geass)
C.C. (Code Geass) | List of Deaths Wiki | Fandom
January 9, 2026 - She is voiced by Yukana for the Japanese dub and Kate Higgins for the English dub. None None None None None None None None None None None None None None None Mao - Shot in the neck by C.C. with a silenced pistol.
Top answer
1 of 1
9

Originally posted at Unix.stackexchange.com, but I can't close vote it to that answer, so this is a copy:

The “kill” meaning of Ctrl+C is very old, I think even older than Unix. Wikipedia traces it back to TOPS-10, which would date it from the late 1960s. The article explains why Ctrl+C was a reasonable choice: in ASCII, which was published in 1963, the corresponding character is ETX, end-of-text. Lacking a character meaning “stop”¹, a character meaning “this segment of input is over” was a reasonable choice to mean “stop the current processing”.

The “copy” meaning of Ctrl+C comes from Xerox PARC, the inventors of copy-paste in its modern form (and most other fundamentals of graphical user interfaces). I don't know exactly when that was, but it must have been the late 1970s. This thread on User Experience Stack Exchange discusses the choice of key bindings; C for copy makes a lot of sense.

There was little reason for PARC to reject Ctrl+C for copy on the basis of the existing meaning in TOPS-10 and Unix terminals. Operating systems and applications were more diverse then, and far fewer people used computers; there was no opportunity nor call for a single standard for key bindings across all applications. Other uses for Ctrl+C in popular applications include page-down in WordStar² and mode-specific command in Emacs. All of these were designed independently, for applications with often different requirements, running in different environments.

You can configure the terminal key bindings with the stty command. The terminal bindings are active when the terminal is in cooked mode³. For example the command stty intr ^G sets the character that sends a SIGINT signal to Ctrl+G instead of Ctrl+C. The ^G character is BEL in ASCII; when sent to a terminal, it means “ring the bell”. It's the character that Emacs uses for “interrupt the current operation” (rationale: the application sends BEL to the user via the terminal to interrupt the user; the user sends BEL to the application via the terminal to interrupt the application). It doesn't have a standard meaning when sent to a terminal.

Most shells provide line editing features, so they set the terminal to raw mode. So do full-screen text mode applications. You may need to configure these applications to recognize Ctrl+G instead of Ctrl+C, and some may have non-configurable key bindings. So changing the interrupt character may or may not be practically doable depending on which applications you use.

Another approach could be to configure your terminal to change the byte sequence that it sends for the Ctrl+C keychord, or make it send nothing and instead perform a copy operation. You would also choose a different keychord to send Ctrl+C (if you have a non-laptop PC keyboard, you could use the out-of-the-way Pause/Break key). Not all terminals can be configured in this way.

¹ Ctrl-S (XOFF) means stop, but it's addressed to the terminal, not to the application. ² Next to Ctrl+X for next-line, with Ctrl+E and Ctrl+R for previous-line and page-up; these keys were chosen due to their placement on a QWERTY keyboard. ³ Nitpick: cooked mode is a set of terminal settings, including the interpretation of several characters including one that sends an interrupt signal.

🌐
Reddit
reddit.com › r/cpp_questions › was c++ supposed to 'kill' c?
r/cpp_questions on Reddit: Was C++ supposed to 'kill' C?
February 8, 2023 -

Every year we see one or two languages come out that are branded as hot new C++ replacements that will make it obsolete. Was C++ branded the same in relation to C? Did C++ users have the same attitude towards the language ancestor as rust users to cpp now?

This post isn't about one language being better than the other, I'm just interested in, say, social history of them.

Top answer
1 of 8
44
No, it was never meant to 'kill' C. I went to a lecture many years ago and heard Bjarne Stroustrup talking about C++. He wrote it as a language to solve real world problems which meant he took it down the object oriented route so that code could be expressed as real world objects. The original C++ was, in fact, written in C and the first C++ compilers compiled C++ into C and then from C into Object code. I also remember he was very scathing about Visual C++ as it was at the time. He described it as a language that 'looked like C++'.
2 of 8
12
Was C++ supposed to 'kill' C? No. Every year we see one or two languages come out that are branded as hot new C++ replacements that will make it obsolete. I laugh every time. That's not how markets work. Was C++ branded the same in relation to C? Bjarne and AT&T did not. C was also an AT&T Bell Labs product. The language was invented by Bjarne because he needed a language with adequate first-class support for objects and Smalltalk was found insufficient for his needs. He could have derived his object oriented solution from any language, the only reason he chose to derive from C, in his own words - was to encourage adoption and thus the survival of his main project, which was a network simulation. What good is delivering a solution and inventing a language to do it if your product is the only one that's going to use the language? Certainly over the decades many people have branded C++ as the C killer, people who had no right or place to say such things. Anyone can say anything at any time, but who the fuck are they? Did C++ users have the same attitude towards the language ancestor as rust users to cpp now? Many did. I did, but I was also young and stupid and didn't know enough to know I didn't actually have a vested opinion either way.
Top answer
1 of 2
2

kill(2) is the system call to send a signal to a process there isn't an equivilent to the killall utility.

An easy way to do this in C would be to invoke killall from your C program, using the system(3) library function or possible popen(3).

Alternatively you could read the manual page about the /proc pseudo file system and search for the command names and find the pids yourself.

man 2 kill
man 3 system
man 3 popen
man 5 proc
2 of 2
0

To answer the question in the title, no there is no C library that does this matching. Not even libprocps does this.

killall is a simple program that:

  • works out what you want to match against
  • effectively does ls on /proc looking for directories with only numbers in their name and matches against files under those directories

Due to it being generic (e.g. it doesn't know what match criteria a user will use beforehand) it has lots of matches. You should know what you want to match already. Your question doesn't really say but it sounds like the name or the command line.

I really caution this entire approach. Processes should be really sure about what other processes they are touching. Name is a terrible match as I can trivially fake that. Also consider you may have two users or two systems using the same name, which process should be killed?

PID files or some other method that records the PID on program commencement is much better because you know exactly which process you are talking about (unless they fork)

As Richard points out above, the killall code is GPL2+ so you can reuse it with the same license. The project moved to gitlab though and is at https://gitlab.com/psmisc/psmisc

🌐
LinuxQuestions.org
linuxquestions.org › questions › programming-9 › c-program-to-kill-process-4175444948
C program to kill process
January 10, 2013 - Hi folks, I am trying to write a C program to kill running processing by their process ids.Although,i have been able to get pids,but i cant seem to
🌐
TechCrunch
techcrunch.com › home › death to c, ++
Death to C, ++ | TechCrunch
July 16, 2017 - But it is a plausible and valuable iterative approach, and we are only going to dig ourselves out of our giant collective security hole iteratively, one shovelful of better code and better tooling at a time. The sooner we start digging, the sooner C will slowly oxidize away.
🌐
Code Quoi
codequoi.com › en › creating-and-killing-child-processes-in-c
Creating and Killing Child Processes in C - codequoi
October 22, 2022 - We can compile this code with the -D flag to define an exit status for the child to use, like this: ... It may be a touch sinister, but we can kill our child process if we so desire. To do so, we need to use the kill function of the <signal.h> library to send a signal to the child process that ...
🌐
CS:APP
csapp.cs.cmu.edu › 3e › ics3 › code › ecf › kill.c
kill.c
/* $begin kill */ #include "csapp.h" ... */ printf("control should never reach here!\n"); exit(0); } /* Parent sends a SIGKILL signal to a child */ Kill(pid, SIGKILL); exit(0); } /* $end kill */...