Sponsored Content
Full Discussion: Ping test using python
Top Forums Shell Programming and Scripting Ping test using python Post 302961177 by cjcox on Tuesday 24th of November 2015 10:50:29 PM
Old 11-24-2015
sleep will will make things more interruptible. Even a sleep 1. So, it simply means you could lose one second at most vs not having it, and you can interrupt it (if that's important to you). Makes it more multiprocess friendly.
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help: infinant loop script - host ping test

need to check on some hosts and send an email if there status changes I wanna put together a script in bash that will allow me to check the up/down state of a single host via ping i want it to run in a continuous loop so I can just fire the script and forget about it(dont want cron to drive... (2 Replies)
Discussion started by: zeekblack
2 Replies

2. Shell Programming and Scripting

Test on string containing spacewhile test 1 -eq 1 do read a $a if test $a = quitC then break fi d

This is the code: while test 1 -eq 1 do read a $a if test $a = stop then break fi done I read a command on every loop an execute it. I check if the string equals the word stop to end the loop,but it say that I gave too many arguments to test. For example echo hello. Now the... (1 Reply)
Discussion started by: Max89
1 Replies

3. Shell Programming and Scripting

How to check weather a string is like test* or test* ot *test* in if condition

How to check weather a string is like test* or test* ot *test* in if condition (5 Replies)
Discussion started by: johnjerome
5 Replies

4. Programming

python little ping script

Hi everyone, I'm a newby in the python languages, and I try to make some parallels to shell. My question is how ca I give the information to python that the line 3 "r=...." the string "line" is a variable. import os, re line = "localhost" r = "".join(os.popen("ping line -c... (2 Replies)
Discussion started by: research3
2 Replies

5. Shell Programming and Scripting

Animation Ping on Solaris Like Cisco Ping

Hi, I develop simple animation ping script on Solaris Platform. It is like Cisco ping. Examples and source code are below. bash-3.00$ gokcell 152.155.180.8 30 Sending 30 Ping Packets to 152.155.180.8 !!!!!!!!!!!!!.!!!!!!!!!!!!!!!. % 93.33 success... % 6.66 packet loss...... (1 Reply)
Discussion started by: gokcell
1 Replies

6. Shell Programming and Scripting

python test datetime 30 minutes ago

Hello, RHEL5.5 PYTHON=2.4.3 I have 2 python variables using the datetime module. Here is how I call them: print "Current Time: %s" % now print "LastDownloadTime: %s" % LastDownloadTime Here is an example of an issue. Current Time: 2012-01-05 14:06:09.749240... (2 Replies)
Discussion started by: jaysunn
2 Replies

7. Shell Programming and Scripting

How to get reason for ping failure using perls Net::Ping->new("icmp");?

Hi I am using perl to ping a list of nodes - with script below : $p = Net::Ping->new("icmp"); if ($p->ping($host,1)){ print "$host is alive.\n"; } else { print "$host is unreacheable.\n"; } $p->close();... (4 Replies)
Discussion started by: tavanagh
4 Replies

8. Programming

Ping test sends mail when ping fails

help with bash script! im am working on this script to make sure my server will stay online, so i made this script.. HOSTS="192.168.138.155" COUNT=4 pingtest(){ for myhost in "$@" do ping -c "$COUNT" "$myhost" &&return 1 done return 0 } if pingtest $HOSTS #100% failed... (4 Replies)
Discussion started by: mort3924
4 Replies

9. Programming

Create a C source and compile inside Python 1.4.0 to 3.7.0 in Python for ALL? platforms...

Hi all... As you know I like making code backwards compatible for as many platforms as possible. This Python script was in fact dedicated for the AMIGA A1200 using Pythons 1.4.0, 1.5.2, 1.6.0, 2.0.1, and 2.4.6 as that is all we have for varying levels of upgrades from a HDD and 4MB FastRam... (1 Reply)
Discussion started by: wisecracker
1 Replies
SLEEPQUEUE(9)						   BSD Kernel Developer's Manual					     SLEEPQUEUE(9)

NAME
init_sleepqueues, sleepq_abort, sleepq_add, sleepq_alloc, sleepq_broadcast, sleepq_calc_signal_retval, sleepq_catch_signals, sleepq_free, sleepq_lock, sleepq_lookup, sleepq_release, sleepq_remove, sleepq_signal, sleepq_set_timeout, sleepq_sleepcnt, sleepq_timedwait, sleepq_timedwait_sig, sleepq_type, sleepq_wait, sleepq_wait_sig -- manage the queues of sleeping threads SYNOPSIS
#include <sys/param.h> #include <sys/sleepqueue.h> void init_sleepqueues(void); int sleepq_abort(struct thread *td); void sleepq_add(void *wchan, struct lock_object *lock, const char *wmesg, int flags, int queue); struct sleepqueue * sleepq_alloc(void); int sleepq_broadcast(void *wchan, int flags, int pri, int queue); int sleepq_calc_signal_retval(int sig); int sleepq_catch_signals(void *wchan); void sleepq_free(struct sleepqueue *sq); struct sleepqueue * sleepq_lookup(void *wchan); void sleepq_lock(void *wchan); void sleepq_release(void *wchan); void sleepq_remove(struct thread *td, void *wchan); int sleepq_signal(void *wchan, int flags, int pri, int queue); void sleepq_set_timeout(void *wchan, int timo); u_int sleepq_sleepcnt(void *wchan, int queue); int sleepq_timedwait(void *wchan); int sleepq_timedwait_sig(void *wchan, int signal_caught); int sleepq_type(void *wchan); void sleepq_wait(void *wchan); int sleepq_wait_sig(void *wchan); DESCRIPTION
Sleep queues provide a mechanism for suspending execution of a thread until some condition is met. Each queue is associated with a specific wait channel when it is active, and only one queue may be associated with a wait channel at any given point in time. The implementation of each wait channel splits its sleepqueue into 2 sub-queues in order to enable some optimizations on threads' wakeups. An active queue holds a list of threads that are blocked on the associated wait channel. Threads that are not blocked on a wait channel have an associated inactive sleep queue. When a thread blocks on a wait channel it donates its inactive sleep queue to the wait channel. When a thread is resumed, the wait channel that it was blocked on gives it an inactive sleep queue for later use. The sleepq_alloc() function allocates an inactive sleep queue and is used to assign a sleep queue to a thread during thread creation. The sleepq_free() function frees the resources associated with an inactive sleep queue and is used to free a queue during thread destruction. Active sleep queues are stored in a hash table hashed on the addresses pointed to by wait channels. Each bucket in the hash table contains a sleep queue chain. A sleep queue chain contains a spin mutex and a list of sleep queues that hash to that specific chain. Active sleep queues are protected by their chain's spin mutex. The init_sleepqueues() function initializes the hash table of sleep queue chains. The sleepq_lock() function locks the sleep queue chain associated with wait channel wchan. The sleepq_lookup() returns a pointer to the currently active sleep queue for that wait channel associated with wchan or NULL if there is no active sleep queue associated with argument wchan. It requires the sleep queue chain associated with wchan to have been locked by a prior call to sleepq_lock(). The sleepq_release() function unlocks the sleep queue chain associated with wchan() and is primarily useful when aborting a pending sleep request before one of the wait functions is called. The sleepq_add() function places the current thread on the sleep queue associated with the wait channel wchan. The sleep queue chain associ- ated with argument wchan must be locked by a prior call to sleepq_lock() when this function is called. If a lock is specified via the lock argument, and if the kernel was compiled with options INVARIANTS, then the sleep queue code will perform extra checks to ensure that the lock is used by all threads sleeping on wchan. The wmesg parameter should be a short description of wchan. The flags parameter is a bitmask con- sisting of the type of sleep queue being slept on and zero or more optional flags. The queue parameter specifies the sub-queue, in which the contending thread will be inserted. There are currently three types of sleep queues: SLEEPQ_CONDVAR A sleep queue used to implement condition variables. SLEEPQ_SLEEP A sleep queue used to implement sleep(9), wakeup(9) and wakeup_one(9). SLEEPQ_PAUSE A sleep queue used to implement pause(9). There are currently two optional flag: SLEEPQ_INTERRUPTIBLE The current thread is entering an interruptible sleep. SLEEPQ_STOP_ON_BDRY When thread is entering an interruptible sleep, do not stop it upon arrival of stop action, like SIGSTOP. Wake it up instead. A timeout on the sleep may be specified by calling sleepq_set_timeout() after sleepq_add(). The wchan parameter should be the same value from the preceding call to sleepq_add(), and the sleep queue chain associated with wchan must have been locked by a prior call to sleepq_lock(). The timo parameter should specify the timeout value in ticks. The current thread may be marked interruptible by calling sleepq_catch_signals() with wchan set to the wait channel. This function returns a signal number if there are any pending signals for the current thread and 0 if there is not a pending signal. The sleep queue chain associ- ated with argument wchan should have been locked by a prior call to sleepq_lock(). Once the thread is ready to suspend, one of the wait functions is called to put the current thread to sleep until it is awakened and to con- text switch to another thread. The sleepq_wait() function is used for non-interruptible sleeps that do not have a timeout. The sleepq_timedwait() function is used for non-interruptible sleeps that have had a timeout set via sleepq_set_timeout(). The sleepq_wait_sig() function is used for interruptible sleeps that do not have a timeout. The sleepq_timedwait_sig() function is used for interruptible sleeps that do have a timeout set. The wchan argument to all of the wait functions is the wait channel being slept on. The sleep queue chain asso- ciated with argument wchan needs to have been locked with a prior call to sleepq_lock(). The signal_caught parameter to sleepq_timedwait_sig() specifies if a previous call to sleepq_catch_signals() found a pending signal. When the thread is resumed, the wait functions return a non-zero value if the thread was awakened due to an interrupt other than a signal or a timeout. If the sleep timed out, then EWOULDBLOCK is returned. If the sleep was interrupted by something other than a signal, then some other return value will be returned. If zero is returned after resuming from an interruptible sleep, then sleepq_calc_signal_retval() should be called to determine if the sleep was interrupted by a signal. If so, sleepq_calc_signal_retval() returns ERESTART if the interrupting signal is restartable and EINTR otherwise. If the sleep was not interrupted by a signal, sleepq_calc_signal_retval() will return 0. A sleeping thread is normally resumed by the sleepq_broadcast() and sleepq_signal() functions. The sleepq_signal() function awakens the highest priority thread sleeping on a wait channel while sleepq_broadcast() awakens all of the threads sleeping on a wait channel. The wchan argument specifics which wait channel to awaken. The flags argument must match the sleep queue type contained in the flags argument passed to sleepq_add() by the threads sleeping on the wait channel. If the pri argument does not equal -1, then each thread that is awakened will have its priority raised to pri if it has a lower priority. The sleep queue chain associated with argument wchan must be locked by a prior call to sleepq_lock() before calling any of these functions. The queue argument specifies the sub-queue, from which threads need to be woken up. A thread in an interruptible sleep can be interrupted by another thread via the sleepq_abort() function. The td argument specifies the thread to interrupt. An individual thread can also be awakened from sleeping on a specific wait channel via the sleepq_remove() function. The td argument specifies the thread to awaken and the wchan argument specifies the wait channel to awaken it from. If the thread td is not blocked on the the wait channel wchan then this function will not do anything, even if the thread is asleep on a different wait channel. This function should only be used if one of the other functions above is not sufficient. One possible use is waking up a specific thread from a widely shared sleep channel. The sleepq_sleepcnt() function offer a simple way to retrieve the number of threads sleeping for the specified queue, given a wchan. The sleepq_type() function returns the type of wchan associated to a sleepqueue. The sleepq_abort(), sleepq_broadcast(), and sleepq_signal() functions all return a boolean value. If the return value is true, then at least one thread was resumed that is currently swapped out. The caller is responsible for awakening the scheduler process so that the resumed thread will be swapped back in. This is done by calling the kick_proc0() function after releasing the sleep queue chain lock via a call to sleepq_release(). The sleep queue interface is currently used to implement the sleep(9) and condvar(9) interfaces. Almost all other code in the kernel should use one of those interfaces rather than manipulating sleep queues directly. SEE ALSO
condvar(9), runqueue(9), scheduler(9), sleep(9) BSD
January 25, 2010 BSD
All times are GMT -4. The time now is 08:37 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy