Bash – How to Disable New Process PID Message

bashprocess

It may look like this: [2] 2847. I guess the first digit is just an enumeration of processes created from the shell. The second is the PID. Anyway, I never care about that information so it is just annoying to see. Is there a way to turn it off? (I found that set +bm in .bashrc disabled the process termination message.)

Best Answer

The first number is the job index; job-related commands (jobs, fg, etc.) use them. So for example, if you get the output [2] 2847, you could run fg 2 to foreground that job.

As far as I could tell from skimming the source, there isn't a way to disable the message. The one check it does do is to ensure the shell is interactive, so if you run the command in a non-interactive shell you won't get that output. For example, you could run it in a subshell:

$ (your_command &)

That's equivalent to running the command in an entirely different shell though, so it might have other undesired side-effects

If you're willing to patch bash, you can just get rid of that particular output. In bash 4.2 it's in jobs.c on line 1428:

fprintf (stderr, "[%d] %ld\n", job + 1, (long)pid);

It gets called in other circumstances; if you just want it gone for this particular case, you can comment out execute_cmd.c, line 762:

DESCRIBE_PID (last_made_pid);
Related Question