wait

Wait for all processes with a certain name to finish (in bash)

 ̄綄美尐妖づ 提交于 2019-12-05 19:18:46
I would like to wait in linux (Ubuntu 11.10) for a load of processes to finish. Each of these processes has a different pid but the same name. Is it possible to do this? EDIT: Perhaps I should specify that I don't necessarily know what the pid are, just the process name. EDIT: Thanks for the answers; Kevin's seems to do what I want. However, it doesn't work in the specific application I have, so I've posted a more detailed follow-up question here . wait $(pgrep programName) Ought to do it. wait $(pidof processname) perhaps. As long as you have the pid of these processes: wait $pid_of_process

How can I make Perl wait for child processes started in the background with system()?

一笑奈何 提交于 2019-12-05 18:10:24
问题 I have some Perl code that executes a shell script for multiple parameters, to simplify, I'll just assume that I have code that looks like this: for $p (@a){ system("/path/to/file.sh $p&"); } I'd like to do some more things after that, but I can't find a way to wait for all the child processes to finish before continuing. Converting the code to use fork() would be difficult. Isn't there an easier way? 回答1: Using fork/exec/wait isn't so bad: my @a = (1, 2, 3); for my $p (@a) { my $pid = fork()

wait()和notify()

时光毁灭记忆、已成空白 提交于 2019-12-05 15:09:04
package com.net.wait; /** * 首先要理解notify()和wait(),为什么线程没有纪录这两个方法呢, * 因为这两个方法本来就不属于Thread类,而是属于最底层的object基础类的, * 也就是说不光是Thread,每个对象都有notify和wait的功能, * 为什么?因为他们是用来操纵锁的,而每个对象都有锁,锁是每个对象的基础 * ,既然锁是基础的,那么操纵锁的方法当然也是最基础了. */ class ThreadA { public static void main(String[] args) { ThreadB b = new ThreadB(); b.start(); System.out.println("b is start...."); /** * 意思是定义一个同步块,使用b作为资源锁。 * b.wait();的意思是临时释放锁,并阻塞当前线程, * 好让其他使用同一把锁的线程有机会执行, * 在这里要用同一把锁的就是b线程本身. * 这个线程在执行到一定地方后用notify()通知wait的线程,锁已经用完, * 待notify()所在的同步块运行完之后, * wait所在的线程就可以继续执行 */ synchronized (b)//括号里的b是什么意思,起什么作用? { try { System.out.println(

Linux fork() and wait()

百般思念 提交于 2019-12-05 14:22:26
i have one, bad smelling problem :( i have this code: int main() { pid_t child, parent; int status=0; int i; printf("parent = %d\n", getpid()); for(i=1; i<=5; i++){ if( (child = fork()) == 0){ sleep(i); printf("i=%d, %d\n",i, getpid()); } } wait(0); while( (parent = wait(&status)) > 0){ printf("Exit = %d, child = %d\n", status/256, parent); } } and output is similar to: 1, 21320 2, 21321 Exit = 0, child = 21321 3, 21322 Exit = 0, child = 21322 4, 21323 Exit = 0, child = 21323 5, 21324 Exit = 0, child = 21324 And i think that wait(0) not waiting for all subprocess but only wait for first exit

perl background process

不想你离开。 提交于 2019-12-05 14:07:21
I am trying to run a background process in perl. I create a child process, which is used to call another perl script. I want to run few lines of code parallely with this child process. And after the child process is done.I want to print a line of code. Main script #!/usr/bin/perl $|=1; print "before the child process\n"; my $pid = fork(); if (defined $pid) { system("perl testing.pl"); } print "before wait command\n"; wait(); print "after 20 secs of waiting\n"; testing.pl #!/usr/bin/perl print "inside testing\n"; sleep(20); Expected output before the child process before wait command (should

Spurious wakeups on windows. Is it possible?

自古美人都是妖i 提交于 2019-12-05 13:47:40
I recently learned "Spurious wakeups" Any people say that this problem possible only for some types of Linux PC. I use windows. I wrote test for Spurious wakeups. I got result that it is possible. But I want to show this test for you. Maybe I made mistake somewhere. my initial variant: import java.util.Random; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicInteger; public class TestSpuriousWakeups { static final int MAX_THREADS = 600; static final Object mutex = new Object(); static final CountDownLatch allThreadsStarted = new CountDownLatch(MAX_THREADS); static final

Selenium Wait doesn't wait for Element to be Clickable

核能气质少年 提交于 2019-12-05 12:13:20
I have a page that is dynamically loaded and contains a button. I am trying to wait for the button to be available to be clicked with selenium using the C# bindings. I have the following code: WebDriverWait wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(30)); wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("addInspectionButton"))); var button = Driver.Instance.FindElement(By.Id("addInspectionButton")); button.Click(); this doesn't work though. The click event is never fired. The selenium script doesn't throw an exception alerting that the element with an ID of

Wait until setInterval() is done

ⅰ亾dé卋堺 提交于 2019-12-05 12:05:51
问题 I would like to add a small dice rolling effect to my Javascript code. I think a good ways is to use the setInterval() method. My idea was following code (just for testing): function roleDice() { var i = Math.floor((Math.random() * 25) + 5); var j = i; var test = setInterval(function(){ i--; document.getElementById("dice").src = "./images/dice/dice" + Math.floor((Math.random() * 6) + 1) + ".png"; if(i < 1) { clearInterval(test); } }, 50); } Now I would like to wait for the setInterval until

async wait / non blocking wait in python

只愿长相守 提交于 2019-12-05 07:28:12
问题 i like to output each letter of a string after waiting some time, to get a typewriter effect. for char in string: libtcod.console_print(0,3,3,char) time.sleep(50) But this blocks the main thread, and the program turns inactive. You cant access it anymore until it finishes Note: libtcod is used 回答1: Unless there is something preventing you from doing so, just put it into a thread. import threading import time class Typewriter(threading.Thread): def __init__(self, your_string): threading.Thread

Java Monitors: How to know if wait(long timeout) ended by timeout or by Notify()?

岁酱吖の 提交于 2019-12-05 07:18:14
First, this is a near duplicate of: How to differentiate when wait(long timeout) exit for notify or timeout? But it is a new follow-on question. Having this wait declaration: public final native void wait(long timeout) throws InterruptedException; It could exit by InterruptedException, or by timeout, or because Notify/NotifyAll method was called in another thread, Exception is easy to catch but... My code absolutely needs to know if the exit was from timeout or notify. (In the future, this code needs to be redesigned, but that cannot be done now. So I need to know the reason for the exit from