Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- #include <signal.h>
- #include <iostream>
- #include <memory>
- #include <math.h>
- #include <ctime>
- #include <vector>
- using namespace std;
- void reaction_on_signal(int);
- char* generate_str(int len);
- void reaction_on_stop(int);
- int main()
- {
- srand(time(0));
- std::vector<char*> mem_p;
- signal(SIGINT,reaction_on_signal);
- signal(SIGTSTP,reaction_on_stop);
- int length = 80;
- //length = atoi(getenv("COLUMNS"));
- // if(length)
- std::cout << "Terminal str length:" << length << std::endl;
- try
- {
- while(true)
- {
- char *tmp = generate_str(length);
- std::cout << tmp << std::endl;
- mem_p.push_back(tmp);
- }
- }
- catch(std::bad_alloc)
- {
- std::cout << "mem full" << std::endl;
- }
- return 0;
- }
- void reaction_on_signal(int)
- {
- ;
- }
- void reaction_on_stop(int)
- {
- exit(0);
- }
- char* generate_str(int len)
- {
- char* str = new char[len];
- for(int i=0;i < len; ++i)
- {
- str[i] = (char) (rand() % 126 + 35);
- }
- str[len - 1] = '\0';
- return str;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement