资源简介
lrzsz是一款在linux命令行界面实现快速上传和下载的第三方工具,通过它可以使我们在调试linux的时候非常的方便。
代码片段和文件信息
#include
#include
#include
int main(int argc char **argv)
{
int pidfd1fd2;
sem_id sem1sem2;
sem1=create_sem(1“piperun“);
sem2=create_sem(1“piperun“);
if (sem1 perror(“create_sem“);
exit(1);
}
acquire_sem(sem1);
acquire_sem(sem2);
pid=fork();
if (pid==0) {
fd1=open(“/pipe/1“O_WRONLY|O_CREAT0666);
if (fd1==-1) {
perror(“writer: /pipe/1“);
_exit(1);
}
release_sem(sem1);
/* wait for other side to open the pipe 1 */
acquire_sem(sem2);
/* wait for creation of pipe 2 */
acquire_sem(sem1);
fd2=open(“/pipe/2“O_RDONLY);
if (fd2==-1) {
perror(“/pipe/2“);
_exit(1);
}
release_sem(sem2);
dup2(fd20);
dup2(fd11);
system(argv[2]);
_exit(1);
}
acquire_sem(sem1);
fd1=open(“/pipe/1“O_RDONLY);
release_sem(sem2);
if (fd1==-1) {
perror(“/pipe/1“);
exit(1);
}
fd2=open(“/pipe/2“O_WRONLY|O_CREAT0666);
if (fd2==-1) {
perror(“writer: /pipe/2“);
exit(1);
}
release_sem(sem1);
/* wait for child to open ... */
acquire_sem(sem2);
dup2(fd10);
dup2(fd21);
system(argv[1]);
exit(0);
}
评论
共有 条评论