Francis Lewis
Francis Lewis

Reputation: 8990

Code to simulate a segfault

I’m trying to simulate a segfault so I can see some of the conditions that would happen when one exists for debugging a much more complex script that is segfaulting. The code is run via CLI (cron).

Since this app is written in PHP, does anyone have code that will cause a segfault in PHP? The servers are using PHP 5.3, but I’m running 5.5 and 5.6 on two other servers, so code that creates a segfault in any version would work.

Upvotes: 0

Views: 1007

Answers (1)

user7610
user7610

Reputation: 28939

It is as @Marc B says in comment

kill -11 $pid

or

kill -SIGSEGV $pid

where $pid is the pid of the interpreter running your script. Any script would do, one convenient possibility would be just sleep(60), which gives you 60 seconds to send it a SIGSEGV before it exits cleanly on its own.

Upvotes: 1

Related Questions