Using MOSFET to switch device
No, that won't work. P-channel mosfets require the Gate voltage to be lower than the source voltage by some threshold in order to "turn on".

The Mosfet will still conduct through the body diode so the device will receive a small voltage, not the 0V/24V of an on/off switch.

However, even if you did get the mosfet to act like a "short circuit", you're shorting the device VCC to ground which is wasting a good amount of power to turn off the device.

A better way would be to put the P-channel mosfet in directly inline with the device closer to the 24V source.

This would require the pullup voltage to go up to ~24V (minus the turn on threshold) to turn the mosfet off, so you'll most likely have to add some other circuitry to the MCU pin so it doesn't fry. A potential solution might be to use a second N-Channel mosfet to drive the P-channel mosfet gate pin to ground, then use a pullup resistor to the 24V rail.

Something like this:



VG1 is directly driven by the microcontroller (high voltage is on, low voltage is off). R2 is the load circuitry. T1 is a P-channel mosfet and T2 is an N-channel mosfet. R1 is a pull-up resistor to the 24V rail.

There might be a simpler way to do it, this was just the first thing I thought of.

edit:

If you can have a low-side switch, the switching circuitry will be much simpler: just a single N-channel mosfet with the drain tied to the load, the source tied to ground, and the gate tied to the microcontroller with high voltage being on and low voltage being off.