mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
🆕 在shell中启动另一个程序
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
|
||||
user_apps_sub_dirs=shell
|
||||
user_apps_sub_dirs=shell about
|
||||
|
||||
all:
|
||||
@list='$(user_apps_sub_dirs)'; for subdir in $$list; do \
|
||||
|
@ -1,6 +1,6 @@
|
||||
all: about.o
|
||||
|
||||
ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/about $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T shell.lds
|
||||
ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/about $(shell find . -name "*.o") $(shell find $(sys_libs_dir) -name "*.o") -T about.lds
|
||||
|
||||
objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O elf64-x86-64 $(tmp_output_dir)/about $(output_dir)/about.elf
|
||||
about.o: about.c
|
||||
|
@ -3,5 +3,6 @@
|
||||
int main()
|
||||
{
|
||||
printf("Hello World!\n");
|
||||
exit(0);
|
||||
while(1);
|
||||
}
|
50
user/apps/about/about.lds
Normal file
50
user/apps/about/about.lds
Normal file
@ -0,0 +1,50 @@
|
||||
|
||||
OUTPUT_FORMAT("elf64-x86-64","elf64-x86-64","elf64-x86-64")
|
||||
OUTPUT_ARCH(i386:x86-64)
|
||||
ENTRY(main)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
|
||||
. = 0x800000;
|
||||
|
||||
|
||||
.text :
|
||||
{
|
||||
_text = .;
|
||||
|
||||
*(.text)
|
||||
|
||||
_etext = .;
|
||||
}
|
||||
. = ALIGN(8);
|
||||
|
||||
.data :
|
||||
{
|
||||
_data = .;
|
||||
*(.data)
|
||||
|
||||
_edata = .;
|
||||
}
|
||||
|
||||
|
||||
rodata_start_pa = .;
|
||||
.rodata :
|
||||
{
|
||||
_rodata = .;
|
||||
*(.rodata)
|
||||
_erodata = .;
|
||||
}
|
||||
|
||||
|
||||
.bss :
|
||||
{
|
||||
_bss = .;
|
||||
*(.bss)
|
||||
_ebss = .;
|
||||
}
|
||||
|
||||
_end = .;
|
||||
|
||||
|
||||
}
|
@ -369,16 +369,15 @@ int shell_cmd_exec(int argc, char **argv)
|
||||
{
|
||||
pid_t pid = fork();
|
||||
int retval = 0;
|
||||
printf(" pid=%d \n",pid);
|
||||
// printf(" pid=%d \n",pid);
|
||||
|
||||
while(1);
|
||||
if (pid == 0)
|
||||
{
|
||||
printf("child proc\n");
|
||||
// printf("child proc\n");
|
||||
// 子进程
|
||||
int path_len = 0;
|
||||
char *file_path = get_target_filepath(argv[1], &path_len);
|
||||
printf("before execv, path=%s\n", file_path);
|
||||
// printf("before execv, path=%s, argc=%d\n", file_path, argc);
|
||||
execv(file_path, argv);
|
||||
free(argv);
|
||||
while(1);
|
||||
@ -387,13 +386,13 @@ int shell_cmd_exec(int argc, char **argv)
|
||||
else
|
||||
{
|
||||
printf("parent process wait for pid:[ %d ]\n", pid);
|
||||
while(1);
|
||||
|
||||
waitpid(pid, &retval, 0);
|
||||
printf("parent process wait pid [ %d ], exit code=%d\n", pid, retval);
|
||||
free(argv);
|
||||
}
|
||||
|
||||
while(1);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -42,23 +42,10 @@ void main_loop(int kb_fd)
|
||||
|
||||
unsigned char input_buffer[INPUT_BUFFER_SIZE] = {0};
|
||||
|
||||
sbrk(24);
|
||||
// brk(0x700000000000 + (1<<21));
|
||||
pid_t pid = fork();
|
||||
int retval = 0;
|
||||
|
||||
|
||||
for(int i=0;i<10;++i)
|
||||
printf(" @pid=%d ", pid);
|
||||
|
||||
if(pid == 0)
|
||||
{
|
||||
int a = 1/0;
|
||||
}
|
||||
// 初始化当前工作目录的路径
|
||||
shell_current_path = (char *)malloc(3);
|
||||
|
||||
memset(shell_current_path, 0, 3);
|
||||
memset(shell_current_path, 0, 3);
|
||||
shell_current_path[0] = '/';
|
||||
shell_current_path[1] = '\0';
|
||||
|
||||
|
Reference in New Issue
Block a user