我需要能够:
我正在寻求一个过程,我没有办法检查孩子的execvp是否有效.如果失败了,我需要知道它失败了.目前我正在使用
-1 != waitpid( pid, &status, WNOHANG )
Run Code Online (Sandbox Code Playgroud)
但似乎如果pid进程的execv失败,waitpid不会返回-1.
我该怎么检查?我读了waitpid手册页,但我不清楚; 也许我的英语不够好.
编辑:为了解释更多:
我正在为家庭作业建立自己的终端.我需要输入一个命令字符串,让我们说"ls",然后我必须执行命令.
在子forks之后,子进程调用execvp来执行命令(在我解析字符串之后),并且父进程需要检查命令末尾是否有'&'.
如果命令末尾不存在符号'&',则父进程需要等待子进程执行.
所以我需要知道execvp是否失败了.如果它没有失败,则父使用waitpid等待子进程完成执行.如果失败,那么父母将不会等待孩子.
WebDriverWait wait = new WebDriverWait(driver, 60)
WebElement element = driver.findElement(By.xpath("//div[contains(text(),'Loading...')]"));
System.out.println("Test");
wait.until(ExpectedConditions.not(ExpectedConditions.presenceOfElementLocated(By.xpath("//div[contains(text(),'Loading...')]"))));
System.out.println("Test");
Run Code Online (Sandbox Code Playgroud)
试图等待页面加载完成.第一个"测试"打印在控制台中,下面的例外打印在wait.until语句之外.即使在加载屏幕消失后,wait.until仍在等待.已经尝试过该元素的Staleness并且不起作用,获得相同的超时异常.加载完成后,元素在DOM中不再可用
我正在开发一个c#4.0的WPF桌面应用程序,它必须处理许多长时间运行的操作(从数据库加载数据,计算模拟,优化路由等).
当这些长时间运行的操作在后台运行时,我想显示一个Please-Wait对话框.当显示Please-Wait对话框时,应该锁定应用程序,但只是禁用应用程序窗口不是一个好主意,因为所有DataGrids都将失去其状态(SelectedItem).
到目前为止我的工作但有一些问题:使用Create-factory方法创建一个新的WaitXUI.Create方法需要标题文本和对应该锁定的主机控件的引用.Create方法设置窗口的StartupLocation,标题文本和要锁定的主机:
WaitXUI wait = WaitXUI.Create("Simulation running...", this);
wait.ShowDialog(new Action(() =>
{
// long running operation
}));
Run Code Online (Sandbox Code Playgroud)
使用重载的ShowDialog方法,然后可以显示WaitXUI.ShowDialog重载确实需要一个包装长时间运行操作的Action.
在ShowDialog重载中,我只是在自己的线程中启动Action,然后禁用主机控件(将Opacity设置为0.5并将IsEnabled设置为false)并调用基类的ShowDialog.
public bool? ShowDialog(Action action)
{
bool? result = true;
// start a new thread to start the submitted action
Thread t = new Thread(new ThreadStart(delegate()
{
// start the submitted action
try
{
Dispatcher.UnhandledException += Dispatcher_UnhandledException;
Dispatcher.Invoke(DispatcherPriority.Normal, action);
}
catch (Exception ex)
{
throw ex;
}
finally
{
// close the window
Dispatcher.UnhandledException -= Dispatcher_UnhandledException;
this.DoClose();
}
})); …Run Code Online (Sandbox Code Playgroud) 我提出了一项艰巨的任务.我对硒很新,并且仍然在研究等待元素和类似物的功能.
我必须操纵网站上的一些数据,然后继续操作另一个.问题:操作调用一个脚本,当在后台处理操纵数据时,会出现一个"Saving ..."标签.我必须等到可以进入下一个网站.
所以这就是:我如何等待和元素消失?事情是:它始终存在于DOM中,但只能通过某些脚本显示(我想,见下图).
这就是我尝试但它只是不起作用 - 没有等待,selenium只是进入下一步(并且因为"保存"而被警告问我是否要离开或停留在页面上. ..").
private By savingLableLocator = By.id("lblOrderHeaderSaving");
public boolean waitForSavingDone(By webelementLocator, Integer seconds){
WebDriverWait wait = new WebDriverWait(driver, seconds);
Boolean element = wait.until(ExpectedConditions.invisibilityOfElementLocated(webelementLocator));
return element;
}
Run Code Online (Sandbox Code Playgroud)
更新/解决方案:
我提出了以下解决方案:我构建了自己的方法.基本上它会在循环中检查CssValue是否会发生变化.
循环检查CSSVALUE"display"的一定时间,从"block"变为另一个状态.
public void waitForSavingOrderHeaderDone(Integer _seconds){
WebElement savingLbl = driver.findElement(By.id("lblOrderHeaderSaving"));
for (int second = 0;; second++) {
if (second >= _seconds)
System.out.println("Waiting for changes to be saved...");
try {
if (!("block".equals(savingLbl.getCssValue("display"))))
break;
} catch (Exception e) {
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个vb6 prog来等待创建一个pdf文件.现在我只是暂停3秒:
startTime = Time
endTime = TimeValue(startTime) + TimeValue(TimeSerial(0,0,3))
While endTime > Time
Wend
If FSO.FileExists(sPdfFileName) Then
OkCreatedPDF = True
Else
OkCreatedPDF = False
End If
Run Code Online (Sandbox Code Playgroud)
但有时候pdf创作花费的时间超过3秒.所以我想等待创建文件,但是超时(10秒).我不想延长等待时间,因为这将会运行一千次.
我正在使用 LAN 唤醒在 python 脚本中启动某个服务器。
当我可以成功执行 API 请求时,服务器就在线,例如:
return requests.get(
url + path,
auth=('user', user_password),
headers={'Content-Type':'application/json'},
verify=False,
timeout=0.05
).json()
Run Code Online (Sandbox Code Playgroud)
等待服务器启动过程(直到可以通过 API 访问)而不用循环请求向网络发送垃圾邮件的最佳方法是什么?
所以我在 C 上写了这段代码。我创建了一个父亲,它有两个子进程,其中一个变成了僵尸进程。一秒钟后它退出了,正在等他的父亲结束了。另一个子进程保持孤立状态,然后结束。我的问题是,如果我更改waitfor会发生什么waitpid。
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
int main() {
pid_t pid;
int status, value;
pid = fork();
if (pid > 0) { // Father
pid = fork();
if (pid > 0) { // Father
wait(&status);
value = WEXITSTATUS(status);
if (value == 2)
printf("Child 2");
else if (value == 3)
printf("Child 1");
} else if (pid == 0) { //Child 2 - Orphan
sleep(4);
exit(2);
} else {
exit(1);
} …Run Code Online (Sandbox Code Playgroud) 有一个问题(sh screen - 等待屏幕终止)关于如何在继续之前等待屏幕会话终止。
该解决方案使用循环,但我认为不可能在系统服务脚本中使用循环。
目前我使用的是:
ExecStop=/usr/bin/screen -S starforge -p 0 -X stuff "stop^M"
ExecStop=/bin/sleep 10
Run Code Online (Sandbox Code Playgroud)
通常,我不需要整个 10 秒,但我需要某种方法来知道屏幕是否已经终止
我有一个 docker 入口点脚本,该脚本应该捕获发送到容器中进程的信号。主要应用程序是 tomcat - 嵌入在 docker-entrypoint.sh 中的 java 进程,该进程被传递给 dumb-init。容器中的流程映射如下所示:
root@mycontainer:/usr/local/tomcat/webapps/datarouter-example# ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 05:21 ? 00:00:00 dumb-init -- /docker-entrypoint.sh
root 6 1 0 05:21 ? 00:00:00 bash /docker-entrypoint.sh
root 14 6 1 05:21 ? 00:08:57 /jdk-13.0.1/bin/java -Djava.util.logging.config.file=....
Run Code Online (Sandbox Code Playgroud)
Dockerfile:
FROM maven:3.6.3-jdk-13 as maven_builder
WORKDIR /app
COPY . /app
RUN ["mvn","clean","install","-T","2C","-DskipTests=true"]
FROM tomcat:9.0.31-jdk13-openjdk-buster
ARG dumbInitVersion='1.2.2'
# install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
sudo \ …Run Code Online (Sandbox Code Playgroud) 我正在创建两个 shell 作业,如下所示
\nsleep 5 &\ncompletion_pid=$!\n\nsleep 40 && exit 1 &\nfailure_pid=$! \nRun Code Online (Sandbox Code Playgroud)\n我可以使用's 命令的标志bash来获取第一个作业完成的退出代码-nwait
# capture exit code of the first subprocess to exit\nwait -n $completion_pid $failure_pid\nRun Code Online (Sandbox Code Playgroud)\n然而,这个标志在我的 MacOS Big Sur 版本中似乎不可用wait(可能是因为我正在使用zsh- ?)
\xe2\x96\xb6 wait -n\nwait: job not found: -n\nRun Code Online (Sandbox Code Playgroud)\n是否还有其他可用的替代工具可以执行此操作MacOS?
也许奇怪的是,在调用包含wait -nas bash myscript.sh... 的脚本时,我遇到了相同的错误。