Impossible to guess without more information or hearing it. Knocking can be caused by worn engine bearings, a cracked flex plate, a broken hub on the vibration damper, collapsed lifter, timing chain hitting the cover, dented oil pan, exhaust leak, etc.
Did anything unusual happen just before the noise started? Did the noise start suddenly or did it get gradually louder and louder? Does the noise only occur when the engine cuts out? Are there any times when the noise goes away? Guessing is like asking my doctor to treat my pain without providing any information. Does he treat a stomach ache, a hang nail, or an arrow in my butt? : )
Assuming the noise is not related to the engine cutting out, running the engine low on oil, or changing the oil as seldomly as I do, could lead to damaged engine bearings This will be accompanied by a low oil gauge reading on the dash. The gauge might be bouncing around too.
A cracked hub on the vibration damper, or a damper that is loose, makes a loud knock once per engine revolution. This noise can be minimized by removing the serpentine belt. The change is even more noticeable on older trucks that use V-belts. Sometimes you can see the vibration damper wobble during engine operation if it is loose or broken.
A collapsed lifter or related valve-train problem makes a lighter sounding knock higher up in the engine. If a problem in the oiling system is the cause, most or all lifters will be affected, and it will sound like a busy typewriter.
A cracked flex plate can defy quick diagnosis, but it's becoming more common on all brands of vehicles. This clunking or banging noise can come and go with no set pattern. When you said " WHEN AT AN IDLE THE MOTOR CUTS IN AND OUT" I'm pretty sure you don't mean it stops, then restarts by itself. You must mean it sputters but never completely stops running. A cracked flex plate can cause this because it has an outer ring with notches that are read by the crankshaft position sensor. Those pulses are what the engine computer looks at to determine when to fire an injector and a spark plug. The air gap between the sensor and the ring is critical. As the ring on the flex plate wobbles just a little, the sensor stops detecting the notches so the computer stops firing the spark plugs and fuel injectors. This problem rarely clears up completely.
A leak in the exhaust system is more of a ticking noise and is usually heard during acceleration. Look for a cracked pipe or exhaust manifold or even nothing more than a few loose bolts. Black carbon is often found at the source of the leak.
As a final " can you believe that?&Quot; I had a customer describe the engine knock as only occurring under hard acceleration. It turned out to be his aftermarket fake dual exhaust pipe banging on the frame above the rear axle! It did indeed sound like it was coming from the front.