Take the 2-minute tour ×

People, I see a discussion here segmentation fault vs page fault but what I am want to debate here, is whether whenever a segmentation fault occurs, do we always have a page fault. Anyone with linux kernel code experience can you pleas point the code here too? Thank you.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

Segmentation fault can also occur under following circumstances:






Why page fault occur:

a)Trying to access a virtual memory-address

b)Instruction-operand / instruction-address

c)Read-data/write-data, or fetch-instruction

d)Maybe page is ‘not present’

e)Maybe page is ‘not readable’

f)Maybe page is ‘not writable’

g)Maybe page is ‘not visible’

share|improve this answer
Cool, that's nice exhaustive list for both! –  Varun Jun 9 '12 at 5:39
add comment

Pagefault (aka #PF) is the common cause for segfault (addressing some data at a non-present page, trying to read or write data from a protected page without the according level of privilege, fetching code from a no-execute page, ...).

But segfault can occurs for some other rare reasons. For instance if you try to execute a privileged instruction without the requested current privilege level (CPL). Check this sample:

% cat segfault.c && gcc segfault.c -o segfault
int     main(void)

  return 0;

% ./segfault
Segmentation fault

In this sample, the segfault has nothing to do with memory. The invd instruction is a privileged one (only executable when the CPL is ring0). Thus you can't execute it from the userspace. When executing this instruction, a general-protection fault (aka #GP) exception happens. The kernel catch the exception and send the kill signal to the faulty program.

share|improve this answer
Thnx Benoit, this is the precise clarification I was looking forward to. –  Varun Jun 9 '12 at 5:37
add comment

Your Answer


