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?

2

Odp: jak zatrzymać skrypt na 0.5 sekundy

Zrób sobie pętle na ileś tam obiegów, której wykonanie zajmie 0.5s.

Masz niepotrzebny router, uszkodzony czy nie - chętnie przygarnę go.

3

Odp: jak zatrzymać skrypt na 0.5 sekundy

a nie działa :

sleep 0.5;

właśnie wczoraj wpisywałem w pliki  *.sh

,

4

Odp: jak zatrzymać skrypt na 0.5 sekundy

To z busyboxa/openwrt tylko wartości całkowite przyjmuje.

Masz niepotrzebny router, uszkodzony czy nie - chętnie przygarnę go.

5

Odp: jak zatrzymać skrypt na 0.5 sekundy

Cezary nie jestem za dobry w skryptologii:), podeślesz jakiś przykład zatrzymania na 0,5 sek:)
dziękuje

6

Odp: jak zatrzymać skrypt na 0.5 sekundy

for i in $(seq 100);do j=$((i+1)); done


Zmień sobie te 100 na tyle ile trzeba żeby wykonywało się 0.5s.

Masz niepotrzebny router, uszkodzony czy nie - chętnie przygarnę go.

7

Odp: jak zatrzymać skrypt na 0.5 sekundy

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:

https://forum.openwrt.org/viewtopic.php?id=33774

8

Odp: jak zatrzymać skrypt na 0.5 sekundy

Przecież jest, jak ci nie szkoda miejsca we flash to coreutils-sleep wystarczy doinstalować.

Masz niepotrzebny router, uszkodzony czy nie - chętnie przygarnę go.

9

Odp: jak zatrzymać skrypt na 0.5 sekundy

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).

10 (edytowany przez rusink 2013-03-05 16:41:28)

Odp: jak zatrzymać skrypt na 0.5 sekundy

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)