w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
running multiple process in current shell (using {} ) with atleast one command to be run as background
As & is a valid command delimiter, there is no need for ;. { echo "42" & sleep 3; }

Categories : Bash

In Java What is the exit value of a process which is killed in the background through Linux shell using process id
This is not a Java specific question. The return code will be the same for all Unix systems here (at least I have never seen a Unix system not behaving this way): 128 + the number of the signal which caused the process to terminate. No idea for Windows... Therefore, 130 in your case. In C, you'd check (after a call to waitpid() for instance) whether a process has been terminated by a signal using WIFSIGNALED(status).

Categories : Java

Set the pid of a searched running process (ps -ea | grep }) in shell
PID=$(ps -ea | awk '/<search_term>/,NF=1') Shell script to get the process ID on Linux

Categories : Shell

How to get result from background process linux shell script?
I finally found a working solution using anonymous pipes and bash: #!/bin/bash # this executes a separate shell and opens a new pipe, where the # reading endpoint is fd 3 in our shell and the writing endpoint # stdout of the other process. Note that you don't need the # background operator (&) as exec starts a completely independent process. exec 3< <(./a.sh 2&1) # ... do other stuff # write the contents of the pipe to a variable. If the other process # hasn't already terminated, cat will block. output=$(cat <&3)

Categories : Linux

Running process in the background
I tried transport class and it was really great. Here's the code I used: ssh = paramiko.SSHClient() ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) ssh.connect(hostname = "host_ip", username = "un"], password = "up") channel = ssh.get_transport().open_session() pty = channel.get_pty() shell = ssh.invoke_shell() shell.send("cd /my/directory/; nohup ./exec_name > /dev/null 2>&1 & ") But I still don't know how to kill it using python scripts; I have an open question about it here. EDIT 1: I have solved my problem about killing the process somehow; you can check it.

Categories : Misc

Running process in background
You have an extra &, so : for i in $(< input); do youtube-dl "$i" & done To go further the && operator is used in boolean tests, like : ((1 == 1)) && echo "1 == 1" || echo "1 != 1" always protect your variables with double quotes to prevent bash word splitting ! the backticks are deprecated in 2013 in favor of the $( ) form. It's more readable, and easy to nest.

Categories : Bash

How can a background bash script exit the running shell?
What seems like is happening is that after set -m is run in the script, the next command that is run is forced to be in the foreground process group, which takes the original shell out of the foreground process group. Once that process exits, the shell running the script is now in the foreground process group, but once that shell exits, the original shell doesn't put itself back into the foreground process group because it ran the script in the background. So you now have an interactive shell that is in a background process group. You can see some weird behavior here if you put a sleep at the end of your script so that it doesn't exit immediately. When you run the script in the background you get the terminal prompt back, but now your interactive shell isn't in the foreground process g

Categories : Bash

running a command in shell script in parallel without using background
Jobs don't "just stop" because they're backgrounded, but you have to wait for them to finish to avoid exiting the script before they're done. Documentation

Categories : Shell

Linux Shell, display something while a command is running in the background
Whiptail is a tool to do this for you. It is fairly easy to make it display a progress bar, or other information, for you, while your task completes. In fact, it's the tool used by Debian, and many other distributions, in exactly the same context you're using. Here's a simplified version of the code we use to make aptitude installs friendlier looking: pkg=0 setterm -msg off # Disable kernel messages to this terminal setterm -blank 0 # Disable screen blanking aptitude -y install <list of packages> | tr '[:upper:]' '[:lower:]' | while read x; do case $x in *upgraded*newly*) u=${x%% *} n=${x%% newly installed*} n=${n##*upgraded, } r=${x%% to remove*} r=${r##*installed, } pkgs=$((u*2+n*2+r))

Categories : Linux

Python: running process in the background with ability to kill them
It depends on your application logic. If you just feed the data into the database without any CPU intensive tasks, then most of your application time will be spent on IO and threads would be sufficient. If you are doing some CPU intensive suff then you should use the multiprocessing module so you can use all your CPU cores, which threads wont allow you because of the GIL. Using subprocess would just add an additional task of implementing the same stuff that's already implemented in the multiprocessing module so I would skip that (why reinvent the wheel). And gevents is just an event loop I don't see how will that be better than using threads. But if I'm wrong please correct me, I never used gevent.

Categories : Python

Send command to running node process, get back data from inside the app
Use repl module. There are examples in the doco doing exactly what you need: run JS in the context of your application and return output.

Categories : Node Js

Send notification from a service running in background after application is closed in Android
Notification: NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification.Builder builder = new Notification.Builder( getApplicationContext()); Intent intent = new Intent(getApplicationContext(), YourActivity.class); intent.setAction("notification"); PendingIntent pendingIntent = PendingIntent.getActivity( getApplicationContext(), 0, i intent,PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); builder.setSmallIcon(R.drawable.app_icon) .setContentTitle("Next Appoinment....") .setContentText(response)

Categories : Android

get working php files via power shell
$out = shell_exec('powershell -command "& {Get-WmiObject win32_Process | where-object {($_.CommandLine -like "*php*") } | Select-Object ProcessId,CommandLine,"MMxDelimiter" | Format-List}" < '.__FILE__); foreach (explode("MMxDelimiter :",$out) as $Row) { preg_match_all("/ProcessId[^:]+:[^0-9]+([0-9]+)[^a-z]*CommandLine[^:]+:(.+)/is",$Row,$OutPut); if (trim($OutPut[1][0]) != "") { $Files[] = array("ProcessId"=>$OutPut[1][0],"Command"=>preg_replace("/[ ][ ]+/","",$OutPut[2][0])); } } print_r($Files); I have change < NULL with a real file path < __FILE__ so it is not best solution but working!!!

Categories : PHP

Calculating a to power b (a^b) in shell script
There are multiple problems with your code. I'll address the specific question about exponentiation (a ^ b). can anyone please tell me what am i doing wrong here? expr does not support exponentiation: $ expr 2 + 2 4 $ expr 2 * 2 4 $ expr 2 ^ 2 expr: syntax error There are many ways to work around this. For example if you have Python, you could use it as a powerful calculator (both floating-point and arbitrary-precision integer): $ python -c 'print(2 ** 3)' 8

Categories : Shell

how to compute power value with bash shell
Bash's built-in arithmetic only operates on integers, and doesn't allow a negative exponent for the ** operator. There are a variety of other tools available that can perform floating-point arithmetic. For example: $ c=3.0 $ g=-3.0 $ awk "BEGIN{print $c ** $c}" 27 $ awk "BEGIN{print $c ** $g}" 0.037037 $ perl -e "print $c ** $c, qq( ), $c ** $g, qq( )" 27 0.037037037037037 To store the result in a variable: $ c=$(awk "BEGIN{print $c ** $c}") $ echo $c 27

Categories : Bash

Power Shell: A command as a variable with parameter
Command as string: With Invoke-Expression cmdlet you execute an arbitrary string as a piece of code. It takes the string, compiles it, and executes it. So you do: $path='C: est.exe'; Invoke-Expression "$path /q /v"; As a side note: When you do $path=C: est.exe without the quotes, you are actually assigning the STDOUT of test.exe to the variable $path. You have to make clear to PowerShell that it is actually a string you wish to execute later. Command as script object: If you are concerned with performance, you could also try converting your command to a compiled scriptblock, and execute it with the & call operator. $path='C: est.exe'; $cmd = [scriptblock]::Create("$path /q /v"); & $cmd;

Categories : Powershell

Power Shell test-connection and then get computers name or mac-addr
There are always many ways to do something, one such example: $Pinger = New-Object system.Net.NetworkInformation.Ping $PC = "192.168.1.$i" try{ $ErrorActionPreference = "Stop" $PingResult = $Pinger.send($PC) $ResultAddress = $PingResult.Address $PingStatus = $PingResult.Status $DNSObject = [System.Net.Dns]::GetHostEntry($PC).HostName } catch { } finally { Write-Host "$PC $PingStatus $PingHost $? $DNSObject" } This gives more than you requested, but also I think it might also give you some ideas: .NET is at your disposal, not just native cmdlets and Windows Commands Do use built in operators like $?

Categories : Powershell

c# copy/exists/delete/list, remote, power shell
Quoting from Get-Help New-PSDrive: -Root <String> Specifies the data store location to which a Windows PowerShell drive is mapped. For example, specify a network share (such as \Server01Public), a local directory (such as C:Program Files), or a registry key (such as HKLM:SoftwareMicrosoft). The argument of the parameter -Root must have the form \hostnameshare or \ip_addressshare. No port specification with either hostname or IP address is allowed. The cmdlet requires access to port 445 on the remote host. You probably need to set up a VPN between the two hosts, to make this work.

Categories : C#

how to get process id(pid) from forked child process in shell script
From the Bash manual: ! Expands to the process ID of the most recently executed background (asynchronous) command. i.e., use $!.

Categories : Linux

How to connect to a different team project collection with tfs power tools in windows shell?
If you want just select, delete or modify Workitems, i suggest you to install Team Explorer, this product setup on your Excel Addin , permit to access your datas without Visual Studio, when you connect you can select easily your project collection Command line is not fluent to select or modify data. Note : Before you install check your Excel, and section Addin Team Foundation

Categories : Visual Studio 2010

Running two node servers from a single shell command using a shell script
Your command does not work because you are trying to have two processes running in the same shell. Instead, you should 'spawn' the node processes into different processes. Try this command: node project/rest.js & node static-server.js &

Categories : Node Js

Running a login shell using sudo inside a shell script on Mac OSX
Your shell is interpreting the $HOME variable in the heredoc, before the input reaches the su shell. You need to escape the $: bash-3.2$ sudo su -l root <<EOF > echo $HOME > echo $HOME > EOF /Users/kevin /var/root The real question is why does it work on your Linux box.

Categories : Osx

Format of XML request data for REST POST command via power shell script
I don't think you are constructing the XML via strings correctly. You want to use a "here string" e.g.: $createacl = @" <AclRule xmlns='http://cloud.net/schemas/network'> <name>$newaclname</name> <position>$newaclposition</position> <action>$aclaction</action> <protocol>$protoltype</protocol> <sourceIpRange> <ipAddress>$SourceIP</ipAddress> <netmask>$SourceSubnetMask</netmask> </sourceIpRange> <destinationIpRange> <ipAddress>$DestIP</ipAddress> <netmask>$DestSubnetMask</netmask> </destinationIpRange> <portRange> <type>$portRange</type> <port1>$port1</port1>

Categories : Xml

Is it possible to use "kill" to send a signal to a process without forcing the process to exit?
According to the man pages for kill and signal(7), the best you could hope for would be to stop and then maybe continue. But I don't think that will do what you want. I also question the desire to use "kill", a command whose name makes its intended purpose very clear, to do this. Almost every signal you can send with kill is intended to terminate a process or cause it to dump core. I'm not an expert but I think you are trying to use the wrong tool here.

Categories : Linux

How to trigger an automatic screen lock process on my android phone after a specified process running specified time?
How unlock and lock screen programatically in android Has some excellent information on immediately calling the lock screen. You could implement a system using an alarm manager to trigger this event.

Categories : Android

Running Python script causes Raspberry Pi to lose power
I tried your script. It locks up the rpi at this line GPIO.setup(6,GPIO.IN,pull_up_down=GPIO.PUD_DOWN) GPIO06 isn't one of the pins on the GPIO port. You'd have look at the schematic to see what it's connected to. Looks like it's LAN_RUN. What are you trying to do with it? From elinux.org GPIO06 is LAN_RUN and is available on pad 12 of the footprint for IC3 on the Model A. On Model B, it is in use for the Ethernet function. So unless you have a model A, you shouldn't be using GPIO06

Categories : Python

Is a multi process Java program a single process in the context of the actual machine underneath the JVM it is running on?
You're confused between processes and processors. A JVM counts as a single process on your machine, yes. When you start the JVM it runs as a program and it executes Java byte code. A JVM can address all the processors on you machine. When you start a Thread in Java it executes on an available processor.

Categories : Java

Android app that kills background processes to save power
I don't think that's the right way of handeling the problem. These apps have broadcast receivers, which mean they'll restart the service whenever something happens (i.e. AC plugged in/WiFi turned on), and I don't think there's a way to stop that without root, and actually disabling the broadcast receiver. You could make something that kills it every 5 minutes, but that wouldn't be very battery-friendly.

Categories : Android

Check if a process started with Process.Start is still running?
I found a way to check if one process has the file in his "CommandLine", meaning that it is currently editing the application: private static void OpenProcessIfNeeded(String file) { using (ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process")) { foreach (ManagementObject mo in mos.Get()) { if (mo["CommandLine"] != null && mo["CommandLine"].ToString().IndexOf(file, StringComparison.InvariantCultureIgnoreCase) > -1) { Console.WriteLine("Found!: " + mo["CommandLine"]); return; } } } Process.Start(file); }

Categories : C#

Shell within php or send variable from php to shell
The best option (by far!) would be to modify the external script to accept command line parameters. So instead of shell_exec('sh.sh'); where all variables are embedded, make it into shell_exec("./sh.sh $opt1 $opt2"); where you can pass your variables easily. An example for a bash script to use these arguments would be : #!/bin/bash echo "My $1 will kick your $2 anytime" which will replace $1 with the first argument, and $2 with the second.

Categories : PHP

How can I lock UI while running the long running process in the main UI Thread in WPF (code in C#)
I would do it this way: Make a "global" (seen for UI thread and background thread) object of one of concurrent types. You can make it as singleton or pass an object to both threads All the long running thread does is reading data from concurrent object and process them. If main thread (or any other) need to do anything in background simply adds it to the concurrent collection. This kind of approach in concurrent programming is called Producer-consumer problem

Categories : C#

Background process in android is killed after a phone call or after long time in the background
You can't... this is how the Android OS works. It can kill background processes at any time when memory is low. See Processes and Threads and Activities for more info.

Categories : Android

Background process that will kill the current process
If you use: os.system('/path/to/script.sh &') or subprocess.call('/path/to/script.sh &', shell=True) The process will keep going even if the python script dies. If you are always going to reboot, let the OS kill the parent and you not worry about it.

Categories : Python

Get child process id of already running process
In node.js you can do it via child_process library. There is a pid member function that returns the spawned child's pid. E.g. var spawn = require('child_process').spawn, grep = spawn('grep', ['ssh']); console.log('Spawned child pid: ' + grep.pid); grep.stdin.end(); You can also kill the child process with kill. The pty.js does a fork with a pseudo terminal, which is useful if emulating terminal. Otherwise you should use child_process to spawn/fork new processes.

Categories : C

How to get Process object of already running process?
I believe you want GetProcessesByName. It will return an array of all the processes that match the name you give. array<Process^>^ notepadProcesses = Process::GetProcessesByName("notepad");

Categories : C++

Pass data from class running in the background to an activity currently running
it might be you are updating your UI in another thread rather than your UI thread which is now allowed, so try to run your UI code in runOnUiThread() method runOnUiThread(new Runnable() { @Override public void run() { // your ui code } });

Categories : Android

shell in () is another process?
According to the Special Parameters section of the reference manual, $$ Expands to the process ID of the shell. In a () subshell, it expands to the process ID of the invoking shell, not the subshell. So there's nothing strange about the behavior you observe, it's fully documented. As Ansgar Wiechers rightly observes in a comment, The PID of the subshell can be determined with the variable $BASHPID. The documentation of this will be found in the Bash Variables section of the reference manual. There you'll read: BASHPID expands to the process ID of the current Bash process. This differs from $$ under certain circumstances, such as subshells that do not require Bash to be re-initialized. Thanks Ansgar! Note. I don't really like the reference you're reading.

Categories : Bash

C# Process vs VB6 Shell vs UAC
Like most things in the Framework, .Net's ProcessStartInfo class is a pretty big pile of... code. It wraps a ton of Win32 structures and calls. Classic VB's Shell() function is a much lighter weight wrapper around WinExec() In Kernel32 which is in turn a thin wrapper around CreateProcess() In Kernel32 in 32 and 64 bit Windows. I'm guessing what you really want is to start an external program using ProcessStartInfo without invoking the legacy installer detection heuristics in Shell32. There are two options i can think of: Add a manifest to this second program marking it "Vista aware" via: <requestedExecutionLevel level="asInvoker" uiAccess="false"/> Tell it not to use ShellExecute() but instead CreateProcess() by first setting: Process.UseShellExecute = false; And "Yes Virgini

Categories : C#

shell script to process a folder path
Spaces are not allowed in variable assignation in shell, so : #!/bin/sh P='/mnt/temp/' echo "$P" Q=$(echo "$P" | sed -e "s/^.*(.)$/1/") echo "Q is $Q" echo "${P%?}" And use more quotes, see http://mywiki.wooledge.org/Quotes http://mywiki.wooledge.org/Arguments and http://wiki.bash-hackers.org/syntax/words

Categories : Shell

shell script process termination issue
SIGKILL cannot be trapped by the trap command, or by any process. It is a guarenteed kill signal, that by it's definition cannot be trapped. Thus upgrading you sh/bash will not work anyway.

Categories : Shell



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.