标签: process

C信号来自子进程的父进程

我正在尝试解决子进程运行 execvp() 并且需要让父进程知道它是否返回的问题。因此,在 execvp() 返回后(因为出现错误),我如何告诉父级此特定事件已发生,以便它可以处理它。

有一种方法可以通过我正在使用的管道写入一串文本,然后从父级读取它......但它似乎有点草率。有没有更好的办法?

谢谢!

编辑:这是我正在尝试的一些代码,我似乎无法让读取返回。

int errorPipe[2];
signal( SIGPIPE, SIG_IGN );

int oldflags = fcntl (errorPipe[0], F_GETFD, 0);
oldflags |= FD_CLOEXEC;
fcntl (errorPipe[0], F_SETFD, oldflags);
oldflags = fcntl (errorPipe[1], F_GETFD, 0);
oldflags |= FD_CLOEXEC;
fcntl (errorPipe[1], F_SETFD, oldflags);

pipe( errorPipe );

// in the child..
char *error_message = "exec failed";
write( errorPipe[1], error_message, strlen(error_message)+1 );
exit(-1);

// in the parent
printf("read gives: %d\n", read(errorPipe[0], error_read, MAX_LINE_LENGTH) );
Run Code Online (Sandbox Code Playgroud)

c unix process

0
推荐指数
1
解决办法
3385
查看次数

运行 powershell 命令时出错

如何使用java调用powershell命令。

  try {
        ExecuteWatchdog watchdog = new ExecuteWatchdog(20000);
        Process powerShellProcess = Runtime.getRuntime().exec(
                "powershell.exe \"D:\\testscript.ps1\"");
        if (watchdog != null) {
            watchdog.start(powerShellProcess);
        }
        BufferedReader stdInput = new BufferedReader(new InputStreamReader(
                powerShellProcess.getInputStream()));
        String line;
        System.out.println("Output :");
        while ((line = stdInput.readLine()) != null) {
            System.out.println(line);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

注意:我映射了正确的路径。

我尝试使用上面的代码,但它给出了类似的错误

java.io.IOException: Cannot run program "powershell.exe": CreateProcess error=2, The system cannot find the file specified
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:459)
    at java.lang.Runtime.exec(Runtime.java:593)
    at java.lang.Runtime.exec(Runtime.java:431)
    at java.lang.Runtime.exec(Runtime.java:328)
    at com.powershell.PsJava.main(PsJava.java:17))
Run Code Online (Sandbox Code Playgroud)

任何人都可以请你帮忙。

java powershell process runtime.exec ioexception

0
推荐指数
1
解决办法
7272
查看次数

杀死进程用户名变量?(视窗)

有没有办法只从当前用户使用变量 %username% 杀死进程?

假设我已登录,所以我只想在我的会话中终止进程 cmd.exe,但我需要一个变量。

我试过这个

taskkill /F /FI "%username%" /IM cmd.exe

但这不起作用。

windows cmd process taskkill

0
推荐指数
1
解决办法
7610
查看次数

当我们向pid 1发送停止时,docker如何对待子进程

我目前在Dockerfile中使用ENTRYPOINT ["/sbs/start.sh"].因此,当容器启动时,start.sh作为pid 1运行,而我的start.sh脚本将另外两个子进程跨越到pid1.我的问题是当我向pid1发送docker stop命令时,docker如何处理子进程?孩子的过程会被优雅地停止吗?还是会被强行杀死?

在我们有子进程的情况下,有一个简单的进程管理器和init系统(https://github.com/Yelp/dumb-init或supervisor)来解决这些问题会更好吗?如果是这样,请建议一个轻量级的init系统?或者可以pid1(在我的情况下start.sh)处理这些问题?

输出ps -ef:

root         1     0  0 19:23 ?        00:00:00 /bin/bash /sbs/start.sh

root        13     1  0 19:23 ?        00:00:00 /sbs/bin/envconsul... 

root        20    13  1 19:23 ?        00:00:21 /usr/lib/...
Run Code Online (Sandbox Code Playgroud)

任何帮助表示赞赏.

linux process docker docker-compose

0
推荐指数
1
解决办法
1543
查看次数

启动浏览器进程并传递进程ID以便稍后关闭它

我的例子看起来与此类似:

Process.Start("http://www.webpage.com?processId=");
Run Code Online (Sandbox Code Playgroud)

如何在流程开始之前获取流程ID?或者我可以将一些Guid设置为另一个将持续存在的标识符吗?

c# process

0
推荐指数
1
解决办法
389
查看次数

退出后的Excel Ole Object Still Process List

我有这个代码:

function XlsToStringGrid(AGrid: TStringGrid; AXLSFile: string): Boolean;
const
    xlCellTypeLastCell = $0000000B;
var
    XLApp, Sheet: OLEVariant;
    RangeMatrix: Variant;
    x, y, k, r: Integer;
begin
  Result:=False;
  //Cria Excel- OLE Object
  XLApp:=CreateOleObject('Excel.Application');
  try

      XLApp.Visible:=False;

      XLApp.Workbooks.Open(AXLSFile);
      Sheet:=XLApp.Workbooks[ExtractFileName(AXLSFile)].WorkSheets[1];
      Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate;

      x:=XLApp.ActiveCell.Row;

      y:=XLApp.ActiveCell.Column;

      AGrid.RowCount:=x;
      AGrid.ColCount:=y;

      RangeMatrix:=XLApp.Range['A1', XLApp.Cells.Item[X, Y]].Value;

      k:=1;
      repeat
          for r:=1 to y do
              AGrid.Cells[(r - 1),(k - 1)]:=RangeMatrix[K, R];
          Inc(k,1);
      until k > x;
      RangeMatrix:=Unassigned;
      Result:=True;

  finally

      if not VarIsEmpty(XLApp) then
        begin
          Sheet:=Unassigned;
          XLApp.Workbooks[ExtractFileName(AXLSFile)].Close;
          XLApp.Quit;
          XLAPP:=Unassigned;
        end;
      try freeandnil(XLAPP) except; end;
      try freeandnil(Sheet) except; …
Run Code Online (Sandbox Code Playgroud)

delphi excel ole process delphi-xe7

0
推荐指数
1
解决办法
833
查看次数

如何在Rust中将线程提升为子进程?

我需要编写类似于compiletest的东西.Compiletest通过调用rustc进程并捕获stdout/stderr来工作.我的项目还没有运行二进制文件,所以我需要另一种方法来创建子进程.

我不能使用频道或stdout,因为它不受我的代码控制.

process stderr rust

0
推荐指数
1
解决办法
337
查看次数

运行一个进程来处理特定的函数

我在C中得到了一个包含main函数和另一个函数的代码,并且我创建了一个fork来创建另一个进程.我想让新进程只执行函数,一旦完成执行就会死掉.

我搜索了解决方案,但我没有找到.

c operating-system process

0
推荐指数
1
解决办法
70
查看次数

C中未初始化的局部变量中包含的值究竟是什么?

如果我们在C中有一个带有简单的单位化ìnt变量的函数,我们就知道这个变量可能并不总是初始化为零.相反,它可能包含一些"垃圾"值.

我的问题是:究竟什么代表这个价值?它可能是由之前终止的进程留下的一些信息(未同步的内存)?

如果是,那么这不是一个极其严重的安全漏洞吗?因为以这种方式,任何进程都可以读取使用与当前进程相同的地址空间的进程留下的信息(密码,令牌等).

我的假设是,对于每个新进程,内核将为该新进程分配的内存(至少对于堆栈)归零,然后将可执行文件加载到内存中.那些"垃圾"值实际上值由所产生的加载过程的的当前进程(使得没有办法来访问从使用相同的地址空间的其他进程的任何左数据).

我正在与一些研究员讨论这个话题,我真的想要一个清晰而全面的答案(我确信有一个).我们假设内核是基于debian/centos的.很高兴知道不同内核/ OS-es的行为是否存在差异.

谢谢你.

c linux security stack process

0
推荐指数
1
解决办法
130
查看次数

为什么加入一个线程最终会调用多个线程?

我正在学习有关线程和Linux上C语言中的线程编程的知识。我了解的是,加入线程只是调用线程并等待其执行,就像等待子进程运行一样。但是不知道为什么在尝试加入一个线程时最终会调用两个线程!

#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>

void *start1()
{
    printf("Hello from Thread 1\n");

}

void *start2()
{
    printf("Hello from Thread 2\n");
}

void main()
{
    pthread_t t1,t2;

    pthread_create(&t1,NULL,start1,NULL);
    pthread_create(&t2,NULL,start2,NULL);
    pthread_join(t1,NULL); 
}
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,输​​出如下:

[root@localhost]# ./a.out 
Hello from Thread 1
Hello from Thread 2
Run Code Online (Sandbox Code Playgroud)

我希望它仅调用start1的代码。

multithreading pthreads process

0
推荐指数
1
解决办法
55
查看次数