理解用户空间与内核空间

最近面试被问到了用户空间和内核空间的问题,发现脑子以为懂了和嘴巴说出来之间有一段距离,就用写作来填平吧。 什么是用户空间和内核空间? 在Linux中,系统内存可以分为用户空间(user space)和内核空间(kernel space),用户空间是运...

运维
} // applyThemeToGiscus(theme) } // FIXME: 这会导致无法使用 preferred_color_scheme 以外的主题 const applyThemeToGiscus = (theme) => { // theme = theme === 'auto' ? 'preferred_color_scheme' : theme const cmt = document.getElementById('giscus') if (cmt) { // This works before giscus load. cmt.setAttribute('data-theme', theme) } const iframe = document.querySelector('#comments > section.giscus > iframe') if (iframe) { // This works after giscus loaded. const src = iframe.src const newSrc = src.replace(/theme=[\w]+/, `theme=${theme}`) iframe.src = newSrc } } const switchTheme = () => { // light -> dark -> auto -> light -> ... const currentTheme = document.documentElement.getAttribute('data-theme') let newTheme; switch (currentTheme) { case 'light': newTheme = 'dark' break case 'dark': newTheme = 'auto' break default: newTheme = 'light' } applyTheme(newTheme) window.localStorage.setItem('Stellar.theme', newTheme) utils.dark.mode = newTheme === 'auto' ? (window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") : newTheme; utils.dark.method.toggle.start(); const messages = { light: `切换到浅色模式`, dark: `切换到深色模式`, auto: `切换到跟随系统配色`, } hud?.toast?.(messages[newTheme]) } (() => { // Apply user's preferred theme, if any. const theme = window.localStorage.getItem('Stellar.theme') if (theme !== null) { applyTheme(theme) } else { utils.dark.mode = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; } utils.dark.method.toggle.start(); })()