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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

浅谈shell中的clear命令实现

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

NAME(名稱)

clear - 清除終端屏幕

SYNOPSIS(總覽)

clear

DESCRIPTION(描述)

  • clear可以在允許的情況下清屏.
  • 它會(huì)在環(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”,//清除整個(gè)屏幕,行屬性變成單寬單高,光標(biāo)位置不變

“\x1b[H”,//光標(biāo)移動(dòng)

代碼測試

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

動(dòng)圖展示結(jié)果

系統(tǒng)默認(rèn)是用CTRl + Z 來暫停進(jìn)程,但是我們把SIGTSTP信號(hào)截?cái)?#xff0c;改成CTRl + L 會(huì)有什么效果呢?

#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);} }

實(shí)驗(yàn)結(jié)果

這個(gè)時(shí)候程序退出了。為什么呢

總結(jié)

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

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