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!
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
Last edited by FillYourBrain; 12-14-2006 at 06:14 PM.
"You are stupid! You are stupid! Oh, and don't forget, you are STUPID!" - Dexter
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..."); }
Double Helix STL
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; }
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
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.
Code:#include <stdio.h> void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){ puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9 /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i] ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][ t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}
>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.
My best code is written with the delete key.
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.
Last edited by CornedBee; 12-15-2006 at 04:25 PM.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
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.
My best code is written with the delete key.
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.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.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law