SHARE
TWEET

Untitled

a guest Mar 26th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <unistd.h>
  3. #include <stdlib.h>
  4. #include <signal.h>
  5. #include <time.h>
  6.  
  7. int tstpNo = 0;
  8.  
  9. void sigINT(int signum) {
  10.     printf("\nOdebrano sygnał SIGINT\n");
  11.     exit(0);
  12. }
  13.  
  14. void sigSTP(int signum) {
  15.     tstpNo++;
  16.     if(tstpNo%2 == 1)
  17.         printf("\nOczekuję na CTRL+Z - kontynuacja albo CTR+C - zakończenie programu\n");
  18. }
  19.  
  20. int main() {
  21.     signal(SIGINT, sigINT);
  22.  
  23.     struct sigaction act;
  24.     act.sa_handler = sigSTP;
  25.     sigemptyset(&act.sa_mask);
  26.     act.sa_flags = 0;
  27.     sigaction(SIGTSTP, &act, NULL);
  28.  
  29.     while(1) {
  30.         time_t t = time(NULL);
  31.         struct tm tm = *localtime(&t);
  32.  
  33.         if(tstpNo%2 == 0) {
  34.             printf("%d-%d-%d %d:%d:%d\n", tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec);
  35.             sleep(1);
  36.         }
  37.     }
  38.  
  39.     return 0;
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top