日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

浅谈shell中的clear命令实现

發(fā)布時間:2023/11/30 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 浅谈shell中的clear命令实现 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

NAME(名稱)

clear - 清除終端屏幕

SYNOPSIS(總覽)

clear

DESCRIPTION(描述)

  • clear可以在允許的情況下清屏.
  • 它會在環(huán)境變量中查找終端的類型, 然后到terminfo數(shù)據(jù)庫中找出清屏的方法.
    《man手冊》
#include <stdio.h>int clear_main(int argc, char **argv) {/* This prints the clear screen and move cursor to top-left corner control* characters for VT100 terminals. This means it will not work on* non-VT100 compliant terminals, namely Windows' cmd.exe, but should* work on anything unix-y. */fputs("\x1b[2J\x1b[H", stdout); return 0;

fflush(stdout):清空輸出緩沖區(qū),并把緩沖區(qū)內(nèi)容輸出。

“\x1b[2J”,//清除整個屏幕,行屬性變成單寬單高,光標位置不變

“\x1b[H”,//光標移動

代碼測試

#include <stdio.h> #include <stdlib.h> #include <unistd.h>int main() {int pid = fork();if(pid > 0){while(1){printf(" father \n");sleep(1);}}else if(pid == 0){ while(1){fflush(stdout);fputs("\x1b[2J\x1b[H", stdout);sleep(5);}}else{perror("fork");} }

動圖展示結(jié)果

系統(tǒng)默認是用CTRl + Z 來暫停進程,但是我們把SIGTSTP信號截斷,改成CTRl + L 會有什么效果呢?

#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <signal.h>void sigHandler(int sig) { char * p[8] ;printf("ctrl+z\n");p[0] = "clear";execvp(p[0],p); }int main() {while(1){if(signal(SIGTSTP,sigHandler) == SIG_ERR)perror("signal"),exit(0);} }

實驗結(jié)果

這個時候程序退出了。為什么呢

總結(jié)

以上是生活随笔為你收集整理的浅谈shell中的clear命令实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。