start without inheritance of parents file descriptors - shell

I need to start some process on winXP with "start" command.
Sounds simple.
But is there a way that the started process would not inherit any ports from parent?
I start children in my program using:
system "start x -params"
Now when parent is being killed, I can't start it again because I'm learned by errors that some process is already occupying port (which killed parent was using).
I don't want to use:
createProcess (from winAPI, where this can be setup to not inherit fds)
use python in my start string (or any similar interpreters)
Is there a way to start my child process in a way I want them to start?
Is there any "start" alternative?

So after diggin a while, i've found:
psexec
with commandline like:
psexec -d -s myprogram > logfile.log 2>&1
everything is solved.

powershell -command "Start-Process myprogram.exe"

Related

Terminal - Close all terminal windows/processes

I have a couple cli-based scripts that run for some time.
I'd like another script to 'restart' those other scripts.
I've checked SO for answers, but the scenarios were not applicable enough to mine, as I'm trying to end Terminal processes using Terminal.
Process:
2 cli-based scripts are running (node, python, etc).
3rd script is run and decides whether or not to restart the other 2.
This can't quit Terminal, but has to end current processes.
3rd script then runs an executable that restarts everything.
Currently none of the terminal windows are named, and from reading the other posts, I can see that it may be helpful to do so.
I can mostly set this up, I just could not find a command that would end all other terminal processes and close them.
There are a couple of ways to do this. Most common is having a pidfile.
This file contains the process ID (pid) of the job you want to kill
later on. A simple way to create the pidfile is:
$ node server &
$ echo $! > /tmp/node.pidfile
$! contains the pid of the process that was most recently backgrounded.
Then later on, you kill it like so:
$ kill `cat /tmp/node.pidfile`
You would do similar for the python script.
The other less robust way is to do a killall for each process and assume you are not running similar node or python jobs.
Refer to
What is a .pid file and what does it contain? if you're not familiar with this.
The question headline is quite general, so is my reply
killall bash
or generically
killall processName
eg. killall chrome

How to Turn Off a Program Running from .bash_profile

I am working with a Raspberry Pi running linux, and have modified the .bash_profile file in order to a run a program I've made automatically upon login. This works great, but I was wondering how to turn the program off, since for ctrl+c I would need to be running the program in the terminal.
You can use Kill to terminate program by its process Id, Top command will list all the processes, You can also use Pkill, which will Terminate the process by its name.
-9 option forces process to shut down, so its very commonly used.
Example:
kill -9 "Process ID without Quotation marks"
pkill -9 "Name with Quotation marks (Case Sensitive)"
Check this.
I always use
pkill - f processname

Kill all processes launched inside an xterm when exit

I'm using Cygwin to start some servers.
Each server is launched inside an xterm with a bunch of command like this one:
xterm -e $my_cmd /C &
Is there an easy way to kill all launched children (xterm and their running commands) in a row ?
I want also to be able kill a particular launched command when I close its parent xterm.
Someone knows how to perform that ?
killall xterm? That command is in the psmisc package. Xterm will notify its child process with a SIGHUP ("hangup") before it exits. Normally that will cause the child process to exit too, although some servers interpret that signal differently.

What's the nohup on Windows?

I want to run a Java jar file like this:
java -jar spider.jar
How to run it on the background on Windows?
Like this on Linux:
nohup java -jar spider.jar > /var/tmp/spider.log 2>&1 &
You could use the Windows start command:
start /min java -jar spider.jar
This command is not really the same as nohup; but it might be suitable if you're happy with the Java process running in a separate minimised window. See http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx
On Windows it's not normal that a process terminates once its parent was killed (like Unix-likes do it normally). Therefore there is no direct necessity for something like nohup. If you want to avoid the console window associated with it, you can use javaw but redirection won't work, then.
The only way to get the nohup behavior, where the process still runs after logging off (like for micro-services, analytic tools, server batch jobs etc.), is to run the .bat file with the start javaw -jar ... contents as either a service or a scheduled task.
save the following code to nohup.vbs, and add the directory to PATH.
Set args=Wscript.Arguments
Set ws=CreateObject("wscript.shell")
ws.Run args(0),0,true
then, run:
nohup "java -jar spider.jar > /var/tmp/spider.log"
Note that you should quote the full commands and the redirects.
For windows run following mentioned command in Command Prompt or in Terminal
nohup (file need to run) > (File you need to save the log) 2>&1
Ex:
nohup ./bin/windows/kafka-server-start.bat config/server.properties > ./MyKafka.log 2>&1

How can I find out what a command is executing in Terminal on MacOs

After I run a shell script (which call a bunch a other scripts depend on conditions. which is too complicated to understand), I can execute a command 'gdbclient' at my MacOS terminal.
But when I do 'which gdbclient' and 'alias gdbclient', it shows nothing.
Is there anyway for me to find out what 'gdbclient' is actually doing?
You can open up another terminal window and type: ps
That will list all the running processes.
If your script is running as a different user than the current one, you can use ps -ef to list all running processes.
If you know the PID of the process that ran your script, you can find all child processes via parent PID using ps -f | grep [pid]
You can use the Activity Monitor to check things out pretty thoroughly. To get the right privileges to see everything going on you can do:
sudo open /Applications/Utilities/Activity\ Monitor.app/
Dtrace can give you some helpful information: dtrace
to find process 'gdbclient':
ps aux | grep gdbclient
That wont tell you what it's "doing" but that it's running

Resources