process

Get MainWindowHandle of spawned process in .NET Core

不羁的心 提交于 2021-01-29 11:25:12
问题 I have this code: private static void Start(String path) { var process = Process.Start(new ProcessStartInfo(path) { WindowStyle = ProcessWindowStyle.Maximized, UseShellExecute = true, }); ThreadPool.QueueUserWorkItem(Tick, process); } private static void Tick(Object obj) { var process = (Process) obj; while (true) { Debug.WriteLine($"HWND: {process.MainWindowHandle}"); Thread.Sleep(TimeSpan.FromMilliseconds(10)); } } This starts a process and then displays the MainWindowHandle property every

Bash conditional based on exit code of command

二次信任 提交于 2021-01-29 10:18:21
问题 In Bash, I would like an if statement which is based of the exit code of running a command. For example: #!/bin/bash if [ ./success.sh ]; then echo "First: success!" else echo "First: failure!" fi if [ ./failure.sh ]; then echo "Second: success!" else echo "Second: failure!" fi success.sh #!/bin/bash exit 0 failure.sh #!/bin/bash exit 1 This should print out: First: success! Second: failure! How would I achieve this? Thanks! 回答1: Just remove the brackets: #!/bin/bash if ./success.sh; then

linux kill command -9 vs -15

南笙酒味 提交于 2021-01-29 10:00:56
问题 I have a process that i would like to kill and then restart a service. Someone has written a code to kill the process by writing the following set of scripts ps -ef |grep "process_name" | awk '{print "kill -15 " $2}'> /projects/test/kill.sh #run the kill script /projects/test/kill.sh and then again ps -ef |grep "process_name" | awk '{print "kill -9 " $2}'> /projects/test/kill.sh #run the kill script /projects/test/kill.sh #finally service restart command here # the problem here is that

Problem creating multiple child processes

可紊 提交于 2021-01-29 09:42:03
问题 Im new at process creation etc..so probably a basic question. Im creating a fixed number of child processes, each doing nothing but printing their pid. The problem is in the output that i get. Have a look: int main(){ pid_t pid=0; int i=0,status=0; for(i=0;i<3;i++){ pid=fork(); switch(pid){ case 0:{ //Child printf("\nChild pid: %d",getpid()); exit(0); break; } case -1: {//Error printf("Error occured in fork"); exit(1); break; } default:{ printf("\nParent id: %d",getpid()); printf("\nIts child

Copy or move file into directory with parallel processing from another process

我们两清 提交于 2021-01-29 09:17:55
问题 I'm running two processes on AIX. Process one is generating several files, process two does backups from all files that are in a backup directory. Process one will copy or move the files into the backup directory. Since process two is always running in the background there is the risk of it starting a backup of a file that is still in the process of being copied or moved and therefore incomplete. How can I avoid this problem? 回答1: Process one should create files in another directory (on the

Copy or move file into directory with parallel processing from another process

若如初见. 提交于 2021-01-29 09:07:17
问题 I'm running two processes on AIX. Process one is generating several files, process two does backups from all files that are in a backup directory. Process one will copy or move the files into the backup directory. Since process two is always running in the background there is the risk of it starting a backup of a file that is still in the process of being copied or moved and therefore incomplete. How can I avoid this problem? 回答1: Process one should create files in another directory (on the

How to change linux kernel process priority in programmatic way?

我与影子孤独终老i 提交于 2021-01-29 07:38:39
问题 I found some function 'renice' that changes the nice value of process. But I want to know how to change priority in kernel code . Is it okay that just changing the priority value in sched_entity of process? 回答1: If you want to change the niceness of the process programmatically, I would advise against setting these values in the kernel struct directly. Instead, you can utilize several POSIX functions such as setpriority or pthread_setschedparam . The default scheduler policy on Linux is SCHED

How to change linux kernel process priority in programmatic way?

大兔子大兔子 提交于 2021-01-29 07:37:40
问题 I found some function 'renice' that changes the nice value of process. But I want to know how to change priority in kernel code . Is it okay that just changing the priority value in sched_entity of process? 回答1: If you want to change the niceness of the process programmatically, I would advise against setting these values in the kernel struct directly. Instead, you can utilize several POSIX functions such as setpriority or pthread_setschedparam . The default scheduler policy on Linux is SCHED

C# Process.StandardOutput.ReadLine() hangs

心不动则不痛 提交于 2021-01-29 07:02:30
问题 So basicly the ReadLine() method just hangs right on the last output line. I dont need to end the process. The main goal is to do "cmd-shell" with stdin and stdout (in variables/Printed out). If the same can be achieved with async methods, please, leave it in comments. Thanks in advance. { Process p = new Process() { StartInfo = new ProcessStartInfo("cmd") { UseShellExecute = false, RedirectStandardInput = true, RedirectStandardError = true, RedirectStandardOutput = true, CreateNoWindow =

Do I have to make a new pipe for every pair of processes in C?

怎甘沉沦 提交于 2021-01-29 01:51:29
问题 If I have 4 processes that I want to pipe: process1 | process2 | process3 | process4 do I have to make 3 individual pipes likes this int pipe1[2]; int pipe2[2]; int pipe3[2]; or can I somehow recycle pipe names like in this pseudocode: int pipe1[2]; // we use ONLY two pipe names: pipe1 int pipe2[2]; // and pipe2 pipe(pipe1); // getting 2 file descriptors here pipe(pipe2); // and 2 here for process=1 to 4 if (process==3) // getting 2 new file descriptors for pipe(pipe1); // process3|process4