HOW DO I MAKE IT STOP?

Even after I kill all the processes, it's still there. HALP!

1
2
3
4
5
6
7
#include <iostream>
int main( int argc, char **argv){
        std::cout << "lol\n";
        system (*argv);
        }

Hello zaphraud,

Without testing the code I believe that "*argv" will point to the first element of "argv" which is the file name of the program that you are running.

The "system" call is creating another instance of the program, what seams like an endless loop.

Another good reason not to use "system"anything.

If you have command line parameters that you want to use they start at "argv[1]" not zero.

Not sure what you want to do with this code, but I would say this is not the way to do it.

Hope that helps,

Andy
Hello zaphraud,

After testing the program my run did not produce the results that you describe. Turn out that my path to the ".exe" file fell apart when there spaces in the path that made a mess of things.

As I thought "*agrv" is the same as "*argv[0]", i.e., the path and file name of the program running.

Remove the "system" call and your program would only run once.

Depending on how you run your program you might need something to pause the program to keep the window open before it finishes.

See http://www.cplusplus.com/forum/beginner/1988/ for some ideas.

Hope that helps,

Andy
Ah, I hadn't even considered what might happen if there were spaces in the path. Good catch, thanks! I'm running it under cygwin and didn't have any spaces.

I knew it would be executing itself, but what I can't figure out is why the usual method of dealing with these things doesn't seem to work.
kill `ps | grep recursive | cut -c 1-10`

I'm thinking maybe "system" itself takes a while to get started (a very long time compared to this tiny program?) and whatever it ends up doing doesn't show in the process list until then .. so there would always be a call to "system" struggling to start that wasn't yet listed to be killed, but once it was listed, it almost immediately started another call to system? It didn't run fast enough to bring down the machine or even exhaust the memory, so something was taking a long time to happen.

What's it doing, and why isn't the call to system listed as something else in the process table while it's doing it?
system() is a synchronous function. Generally it won't return until the child process has terminated. I'd expect your program will create new processes that can never terminate normally, until the very very latest one is killed or the system runs out of memory.
You're saying that you're looking at the process list in the system monitor and you're not seeing thousands of hanged processes?
only dozens to hundreds. or if I typed ps right after running the command mentioned above, only a few. Almost as if it was firing up an entire shell just to execute the command (which, I suppose it is..) but none of the processes I would associate with another shell instance are listed, so there's no intermediate (for example, "bash" or system or whatever) to target with the kill command to get that very last process you mentioned.

It doesn't show up in the process table until it's too late. That's what's weird.
You'll have to whip up a quick program that does something equivalent to this:
1
2
3
4
5
6
7
8
9
10
int killed;
do{
    killed = 0;
    for (auto &process : enumerate_all_processes()){
        if (get_name(process) != "my_program")
            continue;
        kill(process);
        killed++;
    }
}while (killed);
Last edited on
Alter the permissions of the executable.

For example:
mbozzi@qzpa ~ % chmod u-x "forkbomb"
mbozzi@qzpa ~ % # To kill residual processes (not necessary here):
mbozzi@qzpa ~ % ps -o"pid=" -C"forkbomb" | xargs kill -TERM
Last edited on
There, we look some problem in given programming such as **argv . It is not a way to describe like int argc, char **argv.

#include <iostream>
int main( int argc, char **argv){
std::cout << "lol\n";
system (*argv);

For more info click :http://www.traininginlucknow.in/best-c-language-training-in-Lucknow.html
alter the permissions (or rename even) is a winner. thanks! This was fun.
Topic archived. No new replies allowed.