Skip to content

Conversation

@adamdecaf
Copy link

With emulation runmqdevserver appears multiple times in a single line of ps output, so we need to count the number of lines with runmqdevserver instead.

Thanks to @master131 for finding this fix.

Issue: #476

@adamdecaf adamdecaf force-pushed the inspect-running-processes-better branch from c332a3f to a9784de Compare May 4, 2023 20:15
With emulation runmqdevserver appears multiple times in a single line of `ps` output, so we need to count the number of lines with runmqdevserver instead. Issue: ibm-messaging#476
@adamdecaf adamdecaf force-pushed the inspect-running-processes-better branch from a9784de to 880d242 Compare May 5, 2023 14:07
out, _, _ := command.Run("ps", "-e", "--format", "cmd")
//if this goes wrong then assume we are the only one
numOfProg := strings.Count(out, programName)
lines := strings.Split(out, "\n")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be easier to change cmd to comm instead.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with comm.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --format cmd will actually list the command with arguments (it is an alias to args), while comm will only list the binary without arguments.
See: https://man7.org/linux/man-pages/man1/ps.1.html#STANDARD_FORMAT_SPECIFIERS

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm that simply switching to comm format should give the desired result:

sh-4.4$ runmqdevserver > /dev/null 2>&1 & [1] 58 sh-4.4$ ps -e --format comm COMMAND sh runmqdevserver ps sh-4.4$ ps -e --format cmd CMD /usr/bin/qemu-x86_64 /bin/sh /bin/sh /usr/bin/qemu-x86_64 /usr/local/bin/runmqdevserver runmqdevserver ps -e --format cmd 
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I've opened a new PR with the simpler fix #527

@adamdecaf adamdecaf closed this Jun 9, 2023
adamdecaf added a commit to adamdecaf/mq-container that referenced this pull request Jun 9, 2023
During emulation the running processes can contain binary names which trip up detecting if a process is already running. Using the comm format will print the running binaries without arguments. Previous: ibm-messaging#524 Issue: ibm-messaging#476
JEFFLUFC pushed a commit that referenced this pull request Dec 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants