Hi guys
This may sound stupid but how would I make a C program from display a single message, never exit and make sure no one can kill the program using Ctrl+C or Ctrl+Z to background it.
Thanks!
Printable View
Hi guys
This may sound stupid but how would I make a C program from display a single message, never exit and make sure no one can kill the program using Ctrl+C or Ctrl+Z to background it.
Thanks!
the operating system pretty much controls the ability to kill a process. If you're talking unix, they can pretty much always kill it with the 'kill' instruction if they have permission. From windows you have the task manager
Thanks for the reply.
In my situation no one would have access to 'kill'
Any idea how to have the program display a message and not automatically exit?
Do a loop around the code and wait for the user to exit
Code:while ( !=getchar() )
{
printf("Look at me...");
}
Maybe something along this line.
Code:#include <stdio.h>
#include <signal.h>
int main (void)
{
signal(SIGINT, SIG_IGN);
puts("message");
fflush(stdout);
for ( ;; ) ;
return 0;
}
You are both geniuses!
Thank you very much!
I still have a lot to learn.
There ought to be a system-dependant way of blocking the console (like what happens for input) and avoiding a loop too. Double check your signals and experiment.
On Unix you might try
This should flood your PID list.Code:main(){while(!fork())sleep(1);}
Either way, try to make it a system service or some critical driver and you can make it rather hard to get rid of.
>display a single message, never exit and make sure no one can kill the program using Ctrl+C or Ctrl+Z to background it.
I'd love to know what benign purpose this behavior has.
Hi jafet thank you I will try that too.
Hi Prelude
I don't know why you are attacking me I'm just trying to make it so no one can steal a script I've made by being able to get into the console and view other files :(
The code jafet posted has only one purpose: demonstrate how a Unix system can be brought down. REALLY brought down. Modify it slightly and it will expand exponentially.
Dave's code does busy waiting forever. It'll eat up all of your CPU power.
I believe swgh's code is also busy waiting. In addition, it floods the console with messages.
None of these have any benign purpose whatsoever. They are dangerous to system stability and interfere with the proper function of the system. The posts should all be deleted.
If you want to achieve what you're doing here on Unix, create a system user that has your script set as the login program. Then, if anyone kills it, all he gets is a login prompt. Suspending simply won't work. You could then modify the system configuration in such a way that before login, it writes a welcome message telling people finding the screen that a previous idiot user tried to kill the program and they should login with the username and password supplied.
Oh, and Prelude is not attacking you.
Hi CornedBee,
Thanks for your input. I'm not trying to create any dangerous code here.
I thought Prelude's comment was meant to be sarcastic.
Are the first 2 bits of code as dangerous as jafet's?
>I thought Prelude's comment was meant to be sarcastic.
The only practical use I could think of for a program that never ends and can't be shut down is clearly malicious. It's certainly possible that my experience has blinded me to benign uses, so I decided to ask you for clarification. I'm sorry if it sounded like an attack.
>I'm just trying to make it so no one can steal a script I've made by being able to get into the console and view other files
Uh, there are much better ways to copy protect your programs than being completely antisocial.
No. They just slow the computer to a crawl, and if they have a high priority, they can be nearly as dangerous. However, it takes only a simple kill command to eliminate the process.Quote:
Originally Posted by newcguy
The problem with jafet's is that it continually spawns new processes. It would take a killall that's fast enough or a kill of a whole process group to destroy it.