You could open the K-5's shutter on Bulb and then use the leaf shutter to trigger the flash and make the exposure, or you could put the leaf-shutter on T (Which is like Bulb, only it locks open) and connect your flash unit to the K5 and fire more or less normally.
There is no way to make these lenses do 'auto stopdown:' they weren't made for SLRs, and they're a number of decades too early for that feature, anyway.
If you trigger the flash with the lens-shutter, you may need to make some allowances for the fact that the shutter's flash synch was designed for nothing more advanced than flashbulbs: which would do a bit of a slower burn than electronic ones. (I seem to remember successfully using one on an old Crown Graphic with that shutter, but I'm not recalling the details of what we could get away with: they open quickly, leaf shutters, but.... You know, I can't recall actually having any problems. I can't test, now because what I have now that's like it has no flash synch.) I'm not sure you'd really want to do that, apart from perhaps using Live View to replicate the focusing-by-ground-glass experience.
But, yes, with a bellows, it can be done:
As for the length of the bellows, no problem, actually, it seems to be in quite a moderate range, and adding extension tubes is actually kind of something that makes things fit up better. I might even advise a lighter and cheaper setup off Ebay, since the lovely old Pentax one shown here is kind of a beast to try and hand-hold.
Anyway, I haven't tested the limits of getting-very-macro, but if you order some plain M42 extension tubes when you get your M42-m39 adapter, extension probably won't be the limiting factor. When you see those old cameras in the movies, they tend to show them extended a lot more for normal shooting than they really would be: they just hand em out as props to extras who don't know how they'd really be used.