Temat: jak zatrzymać skrypt na 0.5 sekundy
Witam , chciałem zatrzymać wykonywanie kolejnych linii w skrypcie na 0.5s, w sleep najmniejsza wartość to 1sekunda. Ma ktoś może jakieś rozwiązanie?
Nie jesteś zalogowany. Proszę się zalogować lub zarejestrować.
eko.one.pl → Oprogramowanie / Software → jak zatrzymać skrypt na 0.5 sekundy
Strony 1
Zaloguj się lub zarejestruj by napisać odpowiedź
Witam , chciałem zatrzymać wykonywanie kolejnych linii w skrypcie na 0.5s, w sleep najmniejsza wartość to 1sekunda. Ma ktoś może jakieś rozwiązanie?
Zrób sobie pętle na ileś tam obiegów, której wykonanie zajmie 0.5s.
a nie działa :
sleep 0.5;
właśnie wczoraj wpisywałem w pliki *.sh
To z busyboxa/openwrt tylko wartości całkowite przyjmuje.
Cezary nie jestem za dobry w skryptologii:), podeślesz jakiś przykład zatrzymania na 0,5 sek:)
dziękuje
for i in $(seq 100);do j=$((i+1)); done
Zmień sobie te 100 na tyle ile trzeba żeby wykonywało się 0.5s.
Normalnie w linuksie jest:
# usleep <mikrosekundy>
ale w OpenWRT standardowo tego nie ma. Podobno można dodać (aktywować) tą komendę we własnej kompilacji busybox:
Przecież jest, jak ci nie szkoda miejsca we flash to coreutils-sleep wystarczy doinstalować.
Jeżeli to jest skrypt, który coś tam raz wykonuje i się kończy to można zastosować pętlę zajmującą procesor na chwilę, ale jeśli to ma być skrypt robiący coś cały czas co 500ms to lepiej doinstalować ten mikrosleep. Sleep nie zajmuje procesora tylko właśnie uwalnia go od zajmowania się tym skryptem na określony czas (tak w uproszczeniu).
A jeśli po prostu skompilować usleep?
usleep.c
/* Implementation of the BSD usleep function using nanosleep.
Copyright (C) 1996, 1997, 1999, 2001, 2003 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <time.h>
#include <unistd.h>
int
usleep (useconds_t useconds)
{
struct timespec ts = { .tv_sec = (long int) (useconds / 1000000),
.tv_nsec = (long int) (useconds % 1000000) * 1000ul };
/* Note the usleep() is a cancellation point. But since we call
nanosleep() which itself is a cancellation point we do not have
to do anything here. */
return __nanosleep (&ts, NULL);
}nanosleep.c
/* Copyright (C) 1996, 1997, 2002 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <errno.h>
#include <time.h>
/* Pause execution for a number of nanoseconds. */
int
__libc_nanosleep (const struct timespec *requested_time,
struct timespec *remaining)
{
__set_errno (ENOSYS);
return -1;
}
stub_warning (nanosleep)
weak_alias (__libc_nanosleep, __nanosleep)
libc_hidden_def (__nanosleep)
weak_alias (__libc_nanosleep, nanosleep)Strony 1
Zaloguj się lub zarejestruj by napisać odpowiedź
eko.one.pl → Oprogramowanie / Software → jak zatrzymać skrypt na 0.5 sekundy
Forum oparte o PunBB, wspierane przez Informer Technologies, Inc