Reputation: 85056
I would like to create an alias that:
I was able to do this by creating an alias like the one below:
alias startSP='cd mydirectory; redis-server;node myApp.js'
The issue is that the node myApp.js
pieces doesn't run until I kill redis. Is there some way that I can start two processes without waiting for the first to finish?
Should I be trying to open a second tab to do this?
Upvotes: 0
Views: 415
Reputation: 642
Why not add a function to your profile instead?
startSP(){
cd /your/directory
redis-server && node myApp.js
}
The && will start make node myApp.js wait for the redis-server to start
Upvotes: 0
Reputation: 37288
I don't have a way to test this, but adding the '&' to run cmd in background should work, i.e.
alias startSP='cd mydirectory ; redis-server & node myApp.js'
You will probably want to add a 2nd &, ie
alias startSP='cd mydirectory ;redis-server & node myApp.js &'
As this will return the prompt to you and you can keep working at your commandline.
edit
There are many ways to kill processes, search here on S.O. If you lucky, you'll be able to do
pkill redis-server
pkill node ...? hm....
There are a lot of ways to get this wrong, so you'll do better to examine your particular case.
If I was going to do this all the time, I would turn startPS
into a function that captured the PIDs returned from using the '&', saved those pids to the environment, and then had a seperate function that could confirm those PIDs existed, AND that they had a high probability of being the correct program, THEN issue the kill.
Note also, that kill -15
is the preferred way to kill a program, giving it the chance to close files, etc.
IHTH.
Upvotes: 3
Reputation: 183361
Instead of ;
, which separates two processes sequentially, you might use &
, which starts one process in the background and then runs the other in the foreground:
alias startSP='cd mydirectory ; redis-server & node myApp.js'
Upvotes: 2