Ask Your Question
1

What's the function of the symbol '&' after roscore?

asked 2014-11-19 08:46:55 -0500

somebodyus gravatar image

updated 2014-11-19 08:49:25 -0500

The statement 'roscore &' offten appears before 'rosparam set /use_sim_time true'.

What's the function of the symbol & after roscore?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-11-19 08:58:28 -0500

gvdhoorn gravatar image

updated 2014-11-19 08:58:51 -0500

This is more of a general Linux question, but from the manpage of bash (likely your shell):

If a command is terminated by the control operator &, the shell executes the command in the background in a subshell. The shell does not wait for the command to finish, and the return status is 0.

In other words: adding the '&' allows you to continue to use the terminal, while roscore is running in the background. If you did not add the '&', roscore would start and all input (into the terminal window) would be directed to roscore. You'd need a second terminal to do your work in.


For reference: man bash.

edit flag offensive delete link more

Comments

Thank you so much.

How do I terminate the roscore?

somebodyus gravatar imagesomebodyus ( 2014-11-19 09:14:44 -0500 )edit

Just Ctrl+c

ROSkinect gravatar imageROSkinect ( 2014-11-19 09:17:23 -0500 )edit

I run other command after roscore &, and I find I can not use Ctrl+C to terminate it.

somebodyus gravatar imagesomebodyus ( 2014-11-19 09:22:31 -0500 )edit

you run it in the same terminal ?

ROSkinect gravatar imageROSkinect ( 2014-11-19 09:28:32 -0500 )edit

Termination of background tasks can be tricky. You could use pkill: pkill roscore. Note that this will kill the first roscore process that it matches.

gvdhoorn gravatar imagegvdhoorn ( 2014-11-19 09:32:11 -0500 )edit

Yes. I run other command such as ls after roscore &, and the terminal can correctly display the files. However, I can not use Ctrl+C to terminate roscore after I run ls.

somebodyus gravatar imagesomebodyus ( 2014-11-19 09:32:49 -0500 )edit

Thank you!

somebodyus gravatar imagesomebodyus ( 2014-11-19 09:33:45 -0500 )edit
4

You can use fg to bring running "jobs" to the "foreground". So if you type jobs you'll see a list of all running jobs. They'll all have a unique number like [#]. So if roscore was job 1, you could type fg %1 and that would bring roscore to the foreground and Ctrl-C could kill it.

jarvisschultz gravatar imagejarvisschultz ( 2014-11-19 10:06:21 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2014-11-19 08:46:55 -0500

Seen: 1,703 times

Last updated: Nov 19 '14