日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

浅谈shell中的clear命令实现

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

NAME(名稱)

clear - 清除終端屏幕

SYNOPSIS(總覽)

clear

DESCRIPTION(描述)

  • clear可以在允許的情況下清屏.
  • 它會在環境變量中查找終端的類型, 然后到terminfo數據庫中找出清屏的方法.
    《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):清空輸出緩沖區,并把緩沖區內容輸出。

“\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");} }

動圖展示結果

系統默認是用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);} }

實驗結果

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

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。