0

I use win10 if it's matters, in bash(git)

I have SH script:

start node ./e2e-tests/apimocker_runner.js & pid1=$!
start npm run protractor -- --binaryPath=./build/appInstaller/win-unpacked/ & pid2=$!

sleep 10
kill $pid1
kill $pid2

when i try kill processes by pid i have error:

bash: kill: (6616) - No such process

As i know in $! we have last child process pid, but this don't work.

Cuz then i type in bash:

start bash & pid=$!
echo $pid

$pid === 1000 (for example)

but if i type

echo $$

in created bash by previous command i have another pid

$$ ==== 1200 (for example)

Also I found what if i type start bash this create non-child process, but i want to create child process and wait for them like wait $pid

How i can do this?

artofatih
  • 183
  • 10
  • There doesn't seem to be a way for Power Shell to be involved here, if it really is, you need to explain how. In the meantime, I changed the title. – tripleee Aug 23 '16 at 03:28
  • Possible duplicate of http://stackoverflow.com/questions/12351702/how-to-write-a-bash-script-to-set-global-environment-variable – tripleee Aug 23 '16 at 03:31
  • Also [don't use `kill -9`](http://www.iki.fi/era/unix/award.html#kill) when just `kill` will do. – tripleee Aug 23 '16 at 07:16

1 Answers1

1

A variable set in one bash instance is not visible in another bash instance which is not its child process (and only then if the parent did export variable to expose it to children).

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • but problem is: i type kill -9 $myPid in 1st bash, where i did start bash – artofatih Aug 23 '16 at 07:07
  • `start bash` starts a different Bash instance. `myPid` contains the PID of that Bash instance (assuming `start` preserves the PID; not sure about this detail). If that's not what you want, describe what you actually want -- code which doesn't do what you expect is an awful way to explain what you *do* expect. – tripleee Aug 23 '16 at 07:17
  • i have 2 scripts, on another computer i should start SH script, then this script call 2 bash console with some command, when i want to kill this 2 process SH: start node ./e2e-tests/... start npm run protractor .. when i want 2 kill this process, i check, pid in called bash, its dofferent from pid what i have in $pid in parent bash – artofatih Aug 23 '16 at 07:20
  • You are adding new code, not explaining the code you have in your question. – tripleee Aug 23 '16 at 07:22
  • I asq how 2 kill process, then write for what i need this. Start script in 2 bash and kill them – artofatih Aug 23 '16 at 07:23
  • Please [edit] your question to explain what *exactly* you are having trouble with. What do you do, how does it fail, what should it look like? If English is not a strong language for you, perhaps this is not a suitable forum for your question. – tripleee Aug 23 '16 at 07:25