Take the 2-minute tour ×

I would like to create an alias that:

  1. changes directories
  2. starts redis
  3. starts a node application

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?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted

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.


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.

  • Are there other copies of redis-server running that you DON'T want to kill?
  • Are there other copies of node running AND then, how do you differniate those.
  • How do you make sure you're killing the 'myApp.js' version of node.

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.


share|improve this answer
Awesome! How would I kill the processes when I'm done if I return to the command line? –  Abe Miessler Nov 27 '12 at 19:59
@AbeMiessler : see my edit. You'll find plenty of discussion here on S.O. for portable ways to kill apps VS quick-and-dirty methods. –  shellter Nov 27 '12 at 20:06
add comment

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:

share|improve this answer
add comment

Why not add a function to your profile instead?

 cd /your/directory
  redis-server && node myApp.js


The && will start make node myApp.js wait for the redis-server to start

share|improve this answer
What would be the benefit of doing this over using an alias? –  Abe Miessler Dec 17 '12 at 16:06
add comment

Your Answer


