[a / b / c / d / e / f / g / gif / h / hr / k / m / o / p / r / s / t / u / v / vg / vm / vmg / vr / vrpg / vst / w / wg] [i / ic] [r9k / s4s / vip / qa] [cm / hm / lgbt / y] [3 / aco / adv / an / bant / biz / cgl / ck / co / diy / fa / fit / gd / hc / his / int / jp / lit / mlp / mu / n / news / out / po / pol / pw / qst / sci / soc / sp / tg / toy / trv / tv / vp / vt / wsg / wsr / x / xs] [Settings] [Search] [Mobile] [Home]
Board
Settings Mobile Home
/g/ - Technology


Thread archived.
You cannot reply anymore.


[Advertise on 4chan]


File: file.jpg (749 KB, 2400x2800)
749 KB
749 KB JPG
So i like to get something in th linux cmd like time out on windows. I really love the way that timeout works.

>Gives you a visual indicator that it is waiting
>Counts the seconds down.
>You can press any key to interupt it and get it back to work.

How do I get this on linux?
>Reee use sleep
Sleep is shit!
Sleep does not give you any visual indicators it is literally the linux VS windows meme in action (the car thing or the guy in the wheelchair).
>>
>>100200039
good morning sir
>>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <termios.h>
struct termios original_termios;
void set_nonblocking_terminal() {
struct termios ttystate;
tcgetattr(STDIN_FILENO, &original_termios); // Store original terminal attributes
tcgetattr(STDIN_FILENO, &ttystate);
ttystate.c_lflag &= ~(ICANON | ECHO); // turn off canonical mode and echo
ttystate.c_cc[VMIN] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
}
void restore_terminal() {
tcsetattr(STDIN_FILENO, TCSANOW, &original_termios);
}
int main(int argc, char *argv[]) {
if (argc != 2) {
printf("Usage: %s <seconds>\n", argv[0]);
return 1;
}
int seconds = atoi(argv[1]);
set_nonblocking_terminal();
atexit(restore_terminal);
for (int i = seconds; i > 0; i--) {
printf("\rWaiting for %d seconds, press a key to continue ... ", i);
fflush(stdout);
struct timeval tv;
tv.tv_sec = 1;
tv.tv_usec = 0;
fd_set rfds;
FD_ZERO(&rfds);
FD_SET(STDIN_FILENO, &rfds);
int retval = select(STDIN_FILENO + 1, &rfds, NULL, NULL, &tv);
if (retval == -1) {
perror("select()");
return 1;
} else if (retval) {
if (FD_ISSET(STDIN_FILENO, &rfds)) {
while (getchar() != EOF);
printf("\n");
return 0;
}
}
}
printf("\n");
return 0;
}

compile with
gcc timeout.c -o timeout
>>
>>100200470
Interesting thanks....
Why did no one write a program like this for loonix already?

Why is this not in all repos???
>>
>>100200506
Uncommon use case. I would make the user hit enter to continue, without the timeout
>>
>>100200824
>Uncommon use case
Then why does windows include it?
>>
>>100200928
To make people stop "sleeping" by pinging 127.0.0.1 once per second they want to wait
>>
>>100201018
HUH?



[Advertise on 4chan]

Delete Post: [File Only] Style:
[Disable Mobile View / Use Desktop Site]

[Enable Mobile View / Use Mobile Site]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.