How do you keep pigs from escaping? You don't. Oh sure, someone may hand you a 2x4 and say... "The first pig that comes out that hole they made, you hit in the head as hard as you can! I'll go get the other ones!" But I couldn't hit a pig in the head! I stood there and tried to look menacing with my longish piece of treated lumber, and the pigs were unimpressed with me.
What else can you do with a piece of lumber to keep a pig in a pen? Nothing. Certainly not poke at it and try to hold it back. Pigs are round, slippery with muck, and cut-throat! It doesn't matter if you had too much courtesy to hit a pig, they'll run right over you and leave you helpless, clutching your lumber while your farm is transformed into an episode of Benny Hill--except with fewer naked chicks and more pigs running about.
Don't be fooled by how cute they are when they're little. If a pig asks to come live with you, you say NO. They're perfectly capable of building houses of straw, wood and bricks. I heard a story about that a time or twenty.