sandy_1111 sandy_1111 - 2 years ago 59
Bash Question

suspend a shell command without pid

I need something like

$command & stop
This should execute a command and suspend it. The application later resumes back the command for complete results.

I understand that job can be suspended with stop signal to the corresponding pid.

$kill -SIGSTOP 12753

When we execute a command, we barely know its pid. There is extra command involved to take a pid and do the required. I want to avoid the extra command and a time interval.

Basically The application is for a measure of network performance. Trigger all the commands put them in halt mode. The halted commands are resumed back as per the kind of traffic needed.

Answer Source

The process ID of the most recently started background command is available in the shell parameter $!:

$ command & kill -SIGSTOP $!
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download