dup

微机原理与接口技术笔记(二)

佐手、 提交于 2019-12-02 19:42:25
目录 转移类指令 循环控制指令 过程调用指令 中断控制指令 处理器控制指令 汇编语言源程序 过程 语句类型 伪指令 数据定义伪指令 符号定义伪指令 段定义伪指令 设定段寄存器伪指令 结束伪指令 过程定义伪指令 宏定义伪指令 调整偏移量伪指令 系统功能调用 单字符输入 字符串输入 单字符输出 字符串输出 返回操作系统功能 上一篇笔记: https://www.cnblogs.com/Tony100K/p/11653755.html 转移类指令 JMP Label 段内直接转移 MOV BX,1200H JMP BX执行完之后 IP=1200H了 MOV BX,1200 JMP WORD PTR[BX]段内间接转移,1200和1201这两个单元送给了IP 段间转移也是32位 JMP FAR Label 间接转移 JMP DWORD PTR[BX] DWORD指32位 低地址送IP,高地址送CS 条件转移范围只有 -128到127 ​ 统计内存数据段中以TABLE为首地址的100个8位带符号数中的正数\负数和零的个数 START: XOR AL,AL MOV PLUS,AL MOV MINUS,AL MOV ZERO,AL LEA SI,TABLE MOV CX,100 CHECK: LODSB OR AL,AL JS X1 JS X2 INC PLUS JMP NEXT X1: INC

Can someone explain what dup() in C does?

余生颓废 提交于 2019-12-02 16:20:58
I know that dup, dup2, dup3 " create a copy of the file descriptor oldfd "(from man pages). However I can't digest it. As I know file descriptors are just numbers to keep track of file locations and their direction(input/output). Wouldn't it be easier to just fd=fd2; Whenever we want to duplicate a file descriptor? And something else.. dup() uses the lowest-numbered unused descriptor for the new descriptor. Does that mean that it can also take as value stdin , stdout or stderr if we assume that we have close() -ed one of those? Just wanted to respond to myself on the second question after

C Shell hanging when dealing with piping

痴心易碎 提交于 2019-12-02 08:15:08
I'm working on a C shell and am having trouble with getting an arbitrary amount of pipes to work. When I run the shell, it hangs on any piping. For some reason, when I do ls -la | sort , it hangs on the sort until I enter stuff and hit Ctrl + D . I know it has something to do with a pipe not closing, but the print statements show that pipes 3,4,5 all get closed in both the parent and child. I've been at this for a few hours and don't know why this doesn't work. Any help would be much appreciated. Original Code: char *current_command; current_command = strtok_r(cmdline_copy, "|", &cmdline_copy)

I/O stream redirection in a Linux shell. How does the shell process a command with redirection?

两盒软妹~` 提交于 2019-12-01 19:03:58
Currently I'm coding a small shell (redirection, pipes, exec, etc.). Been trying to figure out the steps the Linux shell takes in addressing I/O redirection. Some questions on what I need help on: In which direction does the shell read from the command line when it is looking for the redirection? Left to right or the opposite? Uses recursion? What are the cases the shell needs to look for? (not sure if there are many or just a couple that can encompass a lot of variation) Anyways, some I can think of are (correct me if I'm wrong): cmd > file1 # stdout of cmd goes to file cmd file1 > file2 #

How to understand the #dup and #clone operate on objects which referencing other objects?

我与影子孤独终老i 提交于 2019-12-01 10:38:44
I am not sure about the meaning of "...but not the objects they reference" in both the documantion of ruby and rubinus . In ruby-doc , there is the explanation of #clone and #dup behavior saying: Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. Copies the frozen and tainted state of obj. See also the discussion under Object#dup. The same is repeated in the implementation of Rubinius : Copies instance variables, but does not recursively copy the objects they reference. Copies taintedness. I tried out with the following code, but the

How to understand the #dup and #clone operate on objects which referencing other objects?

拈花ヽ惹草 提交于 2019-12-01 06:03:35
问题 I am not sure about the meaning of "...but not the objects they reference" in both the documantion of ruby and rubinus . In ruby-doc, there is the explanation of #clone and #dup behavior saying: Produces a shallow copy of obj—the instance variables of obj are copied, but not the objects they reference. Copies the frozen and tainted state of obj. See also the discussion under Object#dup. The same is repeated in the implementation of Rubinius: Copies instance variables, but does not recursively

Redirect STDOUT and STDERR to socket in C?

笑着哭i 提交于 2019-11-30 22:41:31
I am trying to redirect STDOUT AND STDERR to a socket. I did: if(fork() == 0) { dup2(newsock, STDOUT_FILENO); dup2(newsock, STDERR_FILENO); execvp(); } Somehow, it only showed the first little part of the output. for example, it showed on "mkdir" when I try to execute ls or mkdir. What's the problem? I tried the flollowing it works, but I can only redirect one of STDOUT or STDERR close(1); dup(newsock); Thanks a lot. Your use of dup2() looks fine, so the problem is probably elsewhere. The simple program I threw together to test with does not have the issues you are experiencing, so I'll just

How to redirect the output of system() to a file?

空扰寡人 提交于 2019-11-30 14:19:10
In this C program #include <stdio.h> #include <fcntl.h> int main() { int file = open("Result", O_CREAT|O_WRONLY, S_IRWXU); dup2(stdout, file); system("ls -l"); return 0; } I'm trying to redirect the output of system() to a file, for that i have used dup2 but it is not working. What's wrong with this code ? and, please tell me if there is any better way to do this ? (without using > at the terminal ) stdout is a FILE * pointer of the standard output stream. dup2 expects file descriptor, also you've messed up the parameters order. Use dup2(file, 1); instead. On the better-way-to-do-this part.

Duplicating a Ruby array of strings

﹥>﹥吖頭↗ 提交于 2019-11-30 12:44:47
arr = ["red","green","yellow"] arr2 = arr.clone arr2[0].replace("blue") puts arr.inspect puts arr2.inspect produces: ["blue", "green", "yellow"] ["blue", "green", "yellow"] Is there anyway to do a deep copy of an array of strings, other than using Marshal as i understand that is a hack. I could do: arr2 = [] arr.each do |e| arr2 << e.clone end but it doesn't seem very elegant, or efficient. Thanks Your second solution can be shortened to arr2 = arr.map do |e| e.dup end (unless you actually need the behaviour of clone , it's recommended to use dup instead). Other than that your two solutions

Redirect STDOUT and STDERR to socket in C?

China☆狼群 提交于 2019-11-29 21:17:55
问题 I am trying to redirect STDOUT AND STDERR to a socket. I did: if(fork() == 0) { dup2(newsock, STDOUT_FILENO); dup2(newsock, STDERR_FILENO); execvp(); } Somehow, it only showed the first little part of the output. for example, it showed on "mkdir" when I try to execute ls or mkdir. What's the problem? I tried the flollowing it works, but I can only redirect one of STDOUT or STDERR close(1); dup(newsock); Thanks a lot. 回答1: Your use of dup2() looks fine, so the problem is probably elsewhere.