我写了一个像这样的shell脚本:
#! /bin/sh
...
ls | grep "android"
...
Run Code Online (Sandbox Code Playgroud)
输出是:
android1
android2
xx_android
...
Run Code Online (Sandbox Code Playgroud)
我想在每个文件中添加一个数字,如下所示:
1 android1
2 android2
3 XX_android
...
please choose your dir number:
Run Code Online (Sandbox Code Playgroud)
然后等待用户输入行号x,脚本读回行号然后处理相应的目录.我们怎么能在shell中做到这一点?谢谢 !
我曾经认为所有可重入函数都是线程安全的.但我在Wiki中阅读了Reentrancy页面,它发布了"完全可重入但不是线程安全的代码.因为它不能确保全局数据在执行期间处于一致状态"
int t;
void swap(int *x, int *y)
{
int s;
s = t; // save global variable
t = *x;
*x = *y;
// hardware interrupt might invoke isr() here!
*y = t;
t = s; // restore global variable
}
void isr()
{
int x = 1, y = 2;
swap(&x, &y);
}
Run Code Online (Sandbox Code Playgroud)
我不明白它的解释.为什么这个函数不是线程安全的?是因为int t在线程执行期间全局变量会被更改吗?
b/w __raw_readl/__raw_writel和readl/writellinux内核有什么区别?据说readl/writel比__raw_readl/__raw_writel我们更安全,为什么我们仍然使用__raw_readl/__raw_writel?
在什么情况下我们应该使用这个:__raw_readl/__raw_writel或readl/writel?
我不小心将文件解压缩到一个错误的目录,实际上有数百个文件...现在该目录与原始文件和错误的解压缩文件混乱.我想选择解压缩的文件并使用shell脚本删除它们,例如
$unzip foo.zip -d test_dir
$cd target_dir
$ls test_dir | rm -rf
Run Code Online (Sandbox Code Playgroud)
什么都没发生,没有文件被删除,我的命令出了什么问题?谢谢 !
现在,我使用一种丑陋的方式在shell中创建数组,例如
ARG_ARRAY=(num1 num2 num3 num4 num5 num6 num7 num8 num9 num10)
Run Code Online (Sandbox Code Playgroud)
这可以更优雅吗?像C方式一样,例如
ARG_ARRAY=num[10]
Run Code Online (Sandbox Code Playgroud) 用户线程是否可以直接进入内核线程并调用内核线程?我的意思是,用户空间通过异常进入内核,不调用任何内核线程,而是在内核代码中运行.谢谢 !
我发现在大多数情况下,i_data 只是 i_mapping 的解引用数据,如下所示,为什么在一个 inode 结构中设置两个相同的值?
crash> struct inode ffffffc073c1f360 -o
struct inode {
...
[ffffffc073c1f4a8] struct file_lock *i_flock;
**[ffffffc073c1f4b0] struct address_space i_data;**
[ffffffc073c1f558] struct list_head i_devices;
...
crash> struct inode ffffffc073c1f360
struct inode {
...
i_op = 0xffffffc0007ad1c0 <ext4_file_inode_operations>,
i_sb = 0xffffffc002010000,
**i_mapping = 0xffffffc073c1f4b0,**
i_security = 0xffffffc07230d050,
...
Run Code Online (Sandbox Code Playgroud) 系统调用,异常,除以0等,它们在linux中都有相同的向量条目.如果在x86中,它是0x80,对吗?信号怎么样?操作系统是否也使用int 0x80作为进程的信号?如果有,谁叫它?我们知道如果你想要内核中的陷阱,你必须调用int 0x80或它的包装器,如系统调用,但对于信号的情况,谁调用0x80?
一个shell脚本:
VAR=(aa bb cc)
for i in "${VAR[@]}"
do
echo $i;
done
Run Code Online (Sandbox Code Playgroud)
使用. ar_test.sh它时,它的工作原理.
zhangyf@zhangyf-desktop:~/test$ . ar_test.sh
aa
bb
cc
Run Code Online (Sandbox Code Playgroud)
但是以这种方式失败了,
zhangyf@zhangyf-desktop:~/test$ ./ar_test.sh
./ar_test.sh: 9: Syntax error: "(" unexpected
Run Code Online (Sandbox Code Playgroud)
文件中还有其他行,因此第9行实际上是VAR =(aa bb cc).我知道不同之处在于后者提出了一个新的shell进程,而前者在当前shell中运行脚本,但为什么结果差异如此之大?