Search code examples
jmeterjmeter-plugins

How to get the process ID without using a shell script as arg to OS Process Sampler - Jmeter?


I need to obtain the id of a background process using JMeter.

I'm looking for the output of:

ps -ef | grep [b]ackend.js | awk '{ print $2 }'

I cannot use a shell script because I don't want the script to be a dependency; is there a way to execute the above command in JMeter via OS Process Sampler or another plugin?


Solution

  • I would recommend using -c option of Bash shell, as per the manual page

    -c

    Read and execute commands from the first non-option argument command_string, then exit. If there are arguments after the command_string, the first argument is assigned to $0 and any remaining arguments are assigned to the positional parameters. The assignment to $0 sets the name of the shell, which is used in warning and error messages.

    So:

    1. Add OS Process Sampler
    2. Configure it as follows:

      • Command: /bin/bash
      • First command parameter: -c
      • Second command parameter: ps -ef | grep [b]ackend.js | awk '{ print $2 }'

        Bash Script Os Process simpler

    See How to Run External Commands and Programs Locally and Remotely from JMeter article for more information on launching 3rd-party programs from JMeter tests.