怎么识别网站是用什么语言做的,建设部门电工证查询网站,德阳网站建设,做ppt图表的网站进程的标准输入输出
当主进程fork或exec子进程#xff0c;文件描述符被继承#xff0c;因此0,1,2句柄也被继承#xff0c;从而使得telnet等服务#xff0c;可以做到间接调用别的shell或程序。比如如果是远程登录使用的zsh#xff0c;那么其会重定向到相应的pts
$ ps|gre…进程的标准输入输出
当主进程fork或exec子进程文件描述符被继承因此0,1,2句柄也被继承从而使得telnet等服务可以做到间接调用别的shell或程序。比如如果是远程登录使用的zsh那么其会重定向到相应的pts
$ ps|grep zsh234671 pts/4 00:00:03 zsh
$ cd /proc/234671/fd
$ ls -la
total 0
dr-x------ 2 wsl wsl 0 Jul 6 15:13 .
dr-xr-xr-x 9 wsl wsl 0 Jul 6 15:13 ..
lrwx------ 1 wsl wsl 64 Jul 6 15:13 0 - /dev/pts/4
lrwx------ 1 wsl wsl 64 Jul 6 15:13 1 - /dev/pts/4
lrwx------ 1 wsl wsl 64 Jul 6 15:13 2 - /dev/pts/4
...进程在转为守护进程时可以经0,1,2句柄重定向到/dev/null做到不输出任何信息。
可以使用dump2可以实现重定向功能
c
fd open(./test.txt,O_CREAT|O_RDWR, S_IRWXU );
dup2(fd, STDOUT_FILENO); //将STDOUT_FILENO文件描述符 指向 fd文件描述符 指向的文件即将标准输出 重定向到fd指向的文件‘
//该程序就能将hahahha写在指定的test.txt文件中了
printf(hahahahaha);
close(fd);备注 STDOUT_FILENO、STDIN_FILENO是int型的文件描述符是非负整数属于没有buffer的I/O一般定义为0, 1, 2 在unistd.h定义。
/* Standard file descriptors. */
#define STDIN_FILENO 0 /* Standard input. */
#define STDOUT_FILENO 1 /* Standard output. */
#define STDERR_FILENO 2 /* Standard error output. */open()系统函数返回的是目前未被占用的最小的文件描述符 文件描述符对应的函数是open() read() write() close()等
stdout stdin stderr 是FILE 类型的文件指针属于标准I/O在stdio.h。 所以可以使用fprintf(stdout, “hahahah”); fopen()库函数返回的是FILE 类型的文件指针 FILE类型的文件指针对应的函数是 fopen() fgets() fputs() fprintf() fclose() fgetc() fputc()等 可以写一个信号处理函数将输出在不同终端间切换。或者通过重定向标准输出无名管道的方式实现将子进程的输出用more显示。
终端属性
通过终端属性可以禁用回显
#include stdio.h
#include stdlib.h
#include termios.h
#include unistd.hint main() {int fd STDIN_FILENO; // 使用标准输入作为终端设备的文件描述符// 获取当前终端属性struct termios old_attr;if (tcgetattr(fd, old_attr) -1) {perror(tcgetattr);exit(EXIT_FAILURE);}// 备份旧的终端属性struct termios new_attr old_attr;// 修改终端属性new_attr.c_lflag ~ECHO; // 禁用回显// 设置新的终端属性if (tcsetattr(fd, TCSANOW, new_attr) -1) {perror(tcsetattr);exit(EXIT_FAILURE);}// 读取用户输入并打印char input[100分];printf(Enter your password: );fgets(input, sizeof(input), stdin);printf(Your password: %s, input);// 恢复之前的终端属性if (tcsetattr(fd, TCSANOW, old_attr) -1) {perror(tcsetattr);exit(EXIT_FAILURE);}return 0;
}使用stty -echo就能关闭回显再使用stty echo打开 使用getty打开一个终端 使用tty查看当前是哪个终端。
pilink:/boot$ tty
/dev/ttyS0
pilink:/boot$ sudo su
[sudo] password for pi:
rootlink:/boot# tty
/dev/pts/0
rootlink:/boot# who
pi ttyS0 2024-04-23 22:05
pi pts/0 2024-04-23 23:04参考 linux 终端设置及读写