操作系统实验2:fork()系统调用

news2025/1/18 16:56:32

操作系统实验2:fork()系统调用

文章目录

  • 操作系统实验2:fork()系统调用
  • Task1: fork的基本使用
    • 代码
    • 运行结果
    • 解释
  • Task2: 深入理解fork创建的子进程与父进程的关系
    • 代码
    • 实验结果
    • 现象解释
  • 遇到的问题
    • 1.乌龙事件 vscode
    • 2.the troubles encountered in task1
      • 如何跑.sh文件
      • 编译链接遇到的问题
        • 先解决那个newline的warning
        • 解决crt1.o,crti.o
          • 心态是如何崩溃的
            • 以为自己要成功了!!!
          • chatgpt给我的解决方案
          • 一个可能的原因
          • 还有一些可能的解决方案
          • 摆啦☹,灵机一动, 把gcc版本调回7.5了, 没事啦😋
      • Vscode无法安装 C/C++ Complie run extension
    • 3.the troubles encountered in task2
  • Basic knowledge
    • chmod
      • octal notation 和 symbolic notation
    • 编译链接
    • crti.o 、 crt1.o
    • libgcc_s.so
    • ld
    • ld --verbose
    • ldconfig -p

Task1: fork的基本使用

代码

  • fork.c代码

    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <sys/wait.h>
    int main(void)
    {
        pid_t pid;
        pid = fork();
        if (pid < 0)
        {
            fprintf(stderr, "Fork Failed");
            exit(-1);
        }
        else if (pid == 0)
        {
            printf("I am a child\n");
        }
        else
        {
            wait(NULL);
            printf("I am a parent\n");
            exit(0);
        }
    }
    
    
  • test.sh代码

    #!/bin/bash
    for((i=1;$i<=100;i++));
    do
    echo $i
    ./fork
    done
    

    作用是把fork.c编译链接后的可执行文件fork运行100次

运行结果

  • 运行test.sh

    先child 后 parent

    在这里插入图片描述

  • 去掉wait(NULL)之后再运行test.sh

    不确定

    在这里插入图片描述
    在这里插入图片描述

解释

  • 没有修改的

    When you run the script test.sh, it will execute the fork program 100 times in a loop. Each time fork is called, it creates a new process by calling the fork function. The child process will print “I am a child” and the parent process will wait for the child to finish before printing “I am a parent” and exiting.

    Therefore, you will see the output “I am a child” and “I am a parent” being printed 100 times, with the child process outputting first and the parent process outputting second each time. The parent process will wait for the child process to finish before outputting its message, so the messages will be printed in pairs.

    It’s important to note that the child process is a copy of the parent process, so it will have its own separate memory space and run independently of the parent process. The wait function is used to synchronize the parent and child processes, allowing the parent to wait for the child to finish before continuing.

  • Now I modify fork.c with the wait(NULL) line commented out , I run test.sh again. What will happen

    If you comment out the wait(NULL) line in fork.c, the parent process will no longer wait for the child process to finish before continuing. This means that the parent process will output its message “I am a parent” immediately after the child process starts, rather than waiting for the child process to finish.

    As a result, when you run test.sh, you will see the output “I am a parent” and “I am a child” being printed 100 times, with the parent process outputting first and the child process outputting second each time. The messages will no longer be printed in pairs, because the parent process is no longer waiting for the child process to finish before continuing.

    It’s important to note that the child process will still run independently of the parent process, even if the parent process does not wait for it to finish. The wait function is used to synchronize the parent and child processes, but if it is not called, the parent process will continue without waiting for the child to finish.


    If you run the modified program 100 times with the wait(NULL) line commented out, you may see different results each time you run the program. This is because the fork() function creates a new process by duplicating the calling process, and the behavior of the child process is not deterministic.

    Here are some possible outcomes when running the program 100 times without the wait(NULL) line:

  1. In some runs, you may see the child process print “I am a child” and the parent process print “I am a parent”, followed by the program exiting. This is the expected behavior when the wait() function is not called. In this case, the child process runs to completion and then the parent process exits.

  2. In other runs, you may see the child process print “I am a child” and then the parent process print “I am a parent”, but the program does not exit. This is because the parent process is not waiting for the child process to terminate before exiting, so the child process becomes a “zombie” process that is left running in the background.

  3. In some runs, you may see the child process print “I am a child” and then the parent process print “I am a parent”, followed by the program hanging and not exiting. This is because the child process is not terminating, and the parent process is waiting indefinitely for the child process to finish.

    Overall, the behavior of the program when the wait() function is not called is not deterministic and can vary depending on the specific implementation of the fork() function and the scheduling of processes by the operating system.

    In general, it is good practice to use the wait() function to wait for child processes to terminate in order to avoid leaving zombie processes or hanging programs.

Task2: 深入理解fork创建的子进程与父进程的关系

代码

  • task2.c

    #include <stdio.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <sys/wait.h>
    int main(void)
    {
        int i;
        for (i = 0; i < 2; i++)
        {
            fork();
            printf("-");
        }
        wait(NULL);
        wait(NULL);
        return 0;
    }
    

实验结果

突然感觉在CSDN上传博客也面临各种进程冲突哈哈哈,不然也不会那么多图床转换失败

在这里插入图片描述

一开始给的代码没有#include <sys/wait.h>,会报错,详见后文the troubles encountered in task2

现象解释

When you run this code, it will create a process that creates two child processes, and each of those child processes will create another two child processes. This will create a total of 2^3 = 8 processes.

Each process will print a hyphen character (“-”) to the console. The wait() function will cause the parent process to wait for all of its child processes to terminate before continuing.

After all of the child processes have terminated, the parent process will return 0 to indicate that the program has completed successfully.

So, the output of the program will be a string of 8 hyphen characters, followed by a newline character.

遇到的问题

1.乌龙事件 vscode

  • 缘起,在一个终端里面使用code命令出来这个

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-pixE5VV0-1672104821710)(null)]

  • 接着试遍了下面这些博客里的解决方案,依然没有用

    • sudo chmod 777 Code

    • sudo chown -R user:user Code

    • su到root用户

  • 然后我直接去点击vscode图标打开vscode,再关掉,这个时候再去另一个终端里面,用codecode .都正常了…

    或者说就是我那个终端里面有什么权限冲突? 当时我换个终端就行???

codecode .的区别在于 code .是在当前所在路径下打开vscode

  • What’s the diff between code and code . when I wanna open vscode in terminal ?

    The code command is used to open Visual Studio Code from the command line. When you type code followed by a space and then a file or directory name, it will open Visual Studio Code and open the specified file or directory in it.

    For example, if you have a file called main.js in the current directory and you want to open it in Visual Studio Code, you can type code main.js in the terminal. This will open Visual Studio Code and load the main.js file in it.

    If you just type code followed by a space and then press Enter, it will open Visual Studio Code, but it will not open any specific file or directory. Instead, it will just open the default workspace for Visual Studio Code.

    So, the difference between code and code . is that code will open Visual Studio Code without opening any specific file or directory, while code . will open Visual Studio Code and open the current directory in it.

2.the troubles encountered in task1

如何跑.sh文件

  • 一开始直接在终端里面输入./test.sh

    然后遇到这个:bash: ./test.sh: Permission denied

  • 然后我本能反应,加了个sudo : sudo ./test.sh

    还是不行 : sudo: ./test.sh: command not found

  • 于是去查了一下

    To run a .sh file in the terminal, you will need to make the file executable first. You can do this by using the chmod command followed by the executable permission and the file name. For example:

    chmod +x filename.sh
    

    This will give the current user executable permissions for the file.

    Once the file is made executable, you can run it by typing ./filename.sh in the terminal.

  • 果真chmod之后可以

编译链接遇到的问题

  • chmod加完可执行权限之后,运行./test.sh,有如下报错

    在这里插入图片描述

  • 反应过来,目录下当时只有fork.c,没有fork

  • 于是进行编译链接

    gcc -o fork fork.c遇到如下问题

    image-20221226214315928

先解决那个newline的warning

  • The “warning: no newline at end of file” message is typically generated when you are trying to compile a source code file that does not end with a newline character. This can cause problems when the file is edited or processed by certain tools, as it can cause the last line of the file to be treated differently than the rest of the file.

    To fix this warning, you can simply add a newline character at the end of the file. You can do this by opening the file in a text editor and pressing the “Enter” key or “Return” key at the end of the last line of the file.

    It’s also a good idea to make sure that all of your source code files end with a newline character, as this can help prevent similar issues in the future.

  • 于是我去fork.c新加了一行,那个warning没有了

  • 但是下面的还是在

解决crt1.o,crti.o

心态是如何崩溃的
  • StackOverflow的这篇回答里面办法都快试遍了

  • sudo apt install gcc-multilib 之前装过了, update 再重装也无济于事,还是cannot find balabla

  • create a symbolic link:

    sudo ln -s /usr/lib/x86_64-linux-gnu /usr/lib64
    

    这个试了,还是无济于事。

    而且还不知道这个会不会对以后调别的东西产生影响

  • find指令 找出缺失的东西的位置, 然后再添加到LIBRARY_PATH里面

    • https://stackoverflow.com/a/16605434/18159372

    • find之前记得sudo,不然一堆permission denied

      ![image-20221227075716405](https://img-blog.csdnimg.cn/img_convert/ca66490c1bde279586de748b2a262be1.png)
      
    • 继续find

      sudo find / -name crti.o
      sudo find / -name crt1.o
      

      image-20221227075846007

      找出来发现在/usr/lib32,/usr/libx32/usr/lib/x86_64-linux-gnu三个路径下都有

  • 然后那个-lgcc_s,网上没搜到啥解决方案,我问了问chatgpt

    • /usr/bin/ld: cannot find -lgcc_s

    • If you are still getting the “cannot find -lgcc_s” error after specifying the -L/usr/lib flag, it is possible that the gcc_s library is located in a different directory on your system.

      To find the location of the gcc_s library, you can use the find command to search for it. For example:

      find / -name libgcc_s.so
      

      This will search for the libgcc_s.so library file on your system starting from the root directory (/). The find command will print the full path to the file if it finds it.

      image-20221227082403678

      image-20221227085624161

      Once you have found the location of the libgcc_s.so file, you can specify that directory using the -L flag with the gcc compiler. For example:

      gcc -L/path/to/gcc/library -o fork fork.c
      

      Replace /path/to/gcc/library with the actual path to the libgcc_s.so file on your system.

      You may also need to specify the -lc flag to tell gcc to link the C runtime library. For example:

      gcc -L/path/to/gcc/library -lc -o fork fork.c
      
  • 又尝试StackOverflow里面的ld -lgcc_s --verbose

    image-20221227082807073

  • 我甚至想用之前的apt-file search

    可是这太多了,也不知道安装哪个能fix呀

    image-20221227082717523 image-20221227082727715
  • 关于LIBRARY_PATH 和 LD_LBRARY_PATH

    • 根据find 的结果,我加了几个路径到LIBRARY_PATH

      image-20221227083636268

      此时症状疑似有所缓解

      image-20221227083702217

      很奇怪,我在这个终端设置的LIBRARY_PATH,在另一个终端echo的时候,就输不出东西了!?…

      这也是一个遗留问题

      image-20221227083823997

    • LD_LIBRARY_PATH是在这里看到的https://stackoverflow.com/a/32502403/18159372

      • 看着感觉比LIBRARY_PATH更有道理,感觉燃起了希望,但是还是无济于事
以为自己要成功了!!!
  • StackOverflow上面这个让我燃起了希望

    https://stackoverflow.com/a/12385495/18159372

    image-20221227083922001

    • 试了试!

      image-20221227084005360

  • 那么此时,我想,只需要加上-lgcc_s的路径就可以了吧!!!!!!!

    • 赶紧去问问怎么加路径

      How can I use -B to tell several paths to the terminal When I gcc

      To specify multiple paths to include header files when using the gcc compiler, you can use the -I option followed by the path to the directory containing the header files. For example:

      gcc -I/path/to/headers -I/another/path/to/headers main.c
      

      This will tell the compiler to search for header files in the directories /path/to/headers and /another/path/to/headers when compiling the main.c file.

      You can also use the -L option to specify directories to search for libraries when linking, and the -l option to specify the names of libraries to link with. For example:

      gcc -L/path/to/libraries -lmylibrary main.c
      

      This will tell the compiler to search for the library mylibrary in the directory /path/to/libraries when linking the main.c file.

      The -B option, on the other hand, is used to specify the directory in which to look for the gcc compiler and other programs needed during the compilation process. It is not used to specify paths to header files or libraries.

      I wanna use -B option to specify two directories

      The -B option is used to specify the directory in which the gcc compiler and other programs needed during the compilation process are located. You can specify multiple directories by separating them with a colon (:). For example:

      gcc -B/path/to/compiler:/another/path/to/compiler main.c
      

      This will tell the compiler to search for the gcc compiler and other necessary programs in the directories /path/to/compiler and /another/path/to/compiler.

      Note that the -B option is usually not necessary unless you have installed the compiler in a non-standard location or you are using a cross-compiler. In most cases, the gcc compiler will be located in a standard location that is already in your system’s search path, so you do not need to use the -B option.

      Show me an example, I don’t know what another should be repalced

      Here is an example of using the -B option to specify multiple directories to search for the gcc compiler and other necessary programs:

      gcc -B/usr/local/gcc-9.3.0/bin:/usr/local/gcc-9.3.0/libexec main.c
      

      In this example, the gcc compiler and other necessary programs will be searched for in the directories /usr/local/gcc-9.3.0/bin and /usr/local/gcc-9.3.0/libexec. These directories might contain the gcc compiler executable, as well as other programs needed during the compilation process, such as the preprocessor and linker.

      Note that this is just an example, and the directories specified in the -B option will depend on where you have installed the gcc compiler on your system.

  • 照着用冒号分隔,无济于事, 或者说需要找的是-lgcc而不是libgcc_s.so??? 我彻底麻了…
    image-20221227084909191

chatgpt给我的解决方案

这个gcc -L 目前我还没去官方文档查,也不知道是否正确,反正试下来是无效的

  • When I use gcc3.4 to complie and link a .c file , I meet the following problems : /usr/bin/ld: cannot find crt1.o: No such file or directory /usr/bin/ld: cannot find crti.o: No such file or directory

    The “cannot find crt1.o” and “cannot find crti.o” errors are typically caused by a missing or incorrect library path when linking a C program using gcc.

    The crt1.o and crti.o files are object files that are part of the C runtime library and are required for linking C programs on many systems. These files are usually located in the /usr/lib or /usr/lib64 directories.

    To fix these errors, you can try adding the appropriate library path to the gcc command using the -L flag. For example:

    gcc -L/usr/lib -o program file1.o file2.o file3.o
    

    This will tell gcc to search for libraries in the /usr/lib directory, which should include the crt1.o and crti.o files.

    If the crt1.o and crti.o files are located in a different directory, you can specify that directory instead of /usr/lib.

    You may also need to specify the -lc flag to tell gcc to link the C runtime library. For example:

    gcc -L/usr/lib -lc -o program file1.o file2.o file3.o
    
  • 试了/usr/lib32,/usr/libx32这两个路径放在L后面,都没有用

    image-20221227080317038

  • chatgpt还告诉我这个

    • How to help the gcc find the LIBRARY_PATH when compile .c file

    • To tell the gcc compiler to search for libraries in the directories specified by the LIBRARY_PATH environment variable, you can use the -Wl,-rpath flag when compiling and linking your program.

      The -Wl,-rpath flag is a linker flag that tells the linker to add a specified directory to the list of directories that will be searched for shared libraries when running the program.

      For example, to tell gcc to search for libraries in the directories specified by the LIBRARY_PATH variable, you can use the following command:

      gcc -Wl,-rpath=\$ORIGIN -o program file.c
      

      This will compile the file.c source code file and link it into an executable file called program. The -Wl,-rpath=\$ORIGIN flag tells the linker to add the directory where the program is located ($ORIGIN) to the list of directories that will be searched for shared libraries when the program is run.

      The gcc compiler will also search the directories specified by the -L flag and any default library directories when linking your program.

      I hope this helps! Let me know if you have any questions or if you need further assistance.

    试了试,报错变成了 skipping incompatible??

    这个终端里面我 修改了LIBRARY_PATH,所以没报找不到的错误??? ,换了一个终端,又直接not find了 啊啊啊哭

    image-20221227082044167

  • 噢对,还有个忘记录了

    分为两步,先gcc- c fork.c是不报错的, 到-o那一步才会报错

    image-20221227090103888

一个可能的原因

很多网上的帖子都是分为32bit和64bit处理的,所以我总感觉和这个有关系,就是安装的依赖是不是存在一些位数不匹配的冲突之类的

  • 有个同学的gcc3.4是没问题的

    他是看的Ubuntu18.04搭建linux0.11实验环境,里面的setup.sh文件安装的

    [外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-vTwV203O-1672104829623)(null)]

    不对,接着往下看…setup.sh

    好像有个判断,会根据64位和32位自动选择

    image-20221227075018654

    嘶…那问题在哪呢?

  • 在安装gcc的时候少安装了i386的???

    • 汇总一下在实验一里面我按照

    • 我安装的时候是执行的如下(详细见实验一的记录)

      
      wget http://old-releases.ubuntu.com/ubuntu/pool/main/g/gcc-3.4/cpp-3.4_3.4.6-6ubuntu2_amd64.deb
      
      wget http://old-releases.ubuntu.com/ubuntu/pool/main/g/gcc-3.4/gcc-3.4-base_3.4.6-6ubuntu2_amd64.deb
      
      wget http://old-releases.ubuntu.com/ubuntu/pool/main/g/gcc-3.4/gcc-3.4_3.4.6-6ubuntu2_amd64.deb
      sudo dpkg -i cpp-3.4_3.4.6-6ubuntu2_amd64.deb gcc-3.4-base_3.4.6-6ubuntu2_amd64.deb gcc-3.4_3.4.6-6ubuntu2_amd64.deb
      sudo apt install gcc-multilib
      sudo apt install bin86
      sudo apt install lib32z1 libsm-dev:i386 libx11-6:i386 libxpm4:i386 libstdc++6:i386
      
  • 除了换gcc版本之外,另一个可能的解决办法就是重新安装gcc😰

  • 还有个可能的原因,但是感觉可能性不大,我的g++版本和gcc不匹配???

还有一些可能的解决方案
  • 前面只问了google 、 StackOverflow 和 chatgpt,CSDN还没看

  • 先留几个感觉有可能有用的链接,回头再来看看

    • usr/bin/ld: cannot find 错误解决方法

    image-20221227080805544

    • /usr/bin/ld: cannot find -lc错误原因及解决方法

    • cannot find crti.o: No such file or directory

    • https://wiki.debian.org/Multiarch/LibraryPathOverview

    • make lib32 on x86_64 error: “skipping incompatible”

    • https://stackoverflow.com/a/47867637/18159372

    • /usr/bin/ld: cannot find crti.o: No such file or directory

    • cannot find crt1.o No such file or directory的一种解决方法

摆啦☹,灵机一动, 把gcc版本调回7.5了, 没事啦😋
  • 哈哈哈哈哈哈 开摆啦 ,主要是ddl不允许我深入钻研那么久了…

    image-20221227085753620

Vscode无法安装 C/C++ Complie run extension

image-20221226232405261

  • https://stackoverflow.com/questions/71539670/vs-code-error-while-installing-c-c-extension-please-check-the-log-for-more

    • 里面还是安装一些依赖的解决方案
  • 暂时懒得管更多的了…开摆

3.the troubles encountered in task2

image-20221227090931276

The error message “implicit declaration of function ‘wait’; did you mean ‘main’?” indicates that the wait() function is being used in the program, but it has not been properly declared.

To fix this error, you need to include the header file that declares the wait() function in your program. The header file to include is sys/wait.h.

To include this header file, add the following line at the top of your program:

#include <sys/wait.h>

This will declare the wait() function and allow you to use it in your program.

You should also include the <sys/types.h> header file, as the wait() function requires the pid_t type, which is defined in this header file.

After including the necessary header files, your program should compile and run without any issues.

加上头文件就不会warning了,不过加之前也是可以编译链接 运行的

image-20221227091302294

Basic knowledge

chmod

  • chmod is a command used in Unix and Unix-like operating systems to change the permissions of a file or directory. The permissions determine who is able to read, write, and execute a file.

    The chmod command is used to change the permissions of a file or directory by specifying the access rights for the owner, group, and others. The access rights can be specified using either symbolic notation or octal notation.

    Here is an example of using chmod with symbolic notation:

    $ chmod u=rwx,g=rx,o=r file.txt
    

    This command sets the read, write, and execute permissions for the owner (u) to rwx (read, write, execute), the read and execute permissions for the group (g) to rx (read and execute), and the read permission for others (o) to r (read only).

    Here is an example of using chmod with octal notation:

    $ chmod 754 file.txt
    

    This command sets the read, write, and execute permissions for the owner to rwx (7 in octal notation), the read and execute permissions for the group to rx (5 in octal notation), and the read permission for others to r (4 in octal notation).

  • 突然想起前面那个乌龙里面用了chmod 777

    • What means chmod 777 ?

    • When using chmod, the 777 permission set gives read, write, and execute permissions to all users (owner, group, and others).

      For example, the command chmod 777 file.txt would give read, write, and execute permissions to the owner, group, and others for the file file.txt.

      In symbolic notation, this would be equivalent to chmod u=rwx,g=rwx,o=rwx file.txt.

      It is generally not recommended to use the 777 permission set, as it gives full access to everyone and may pose a security risk. Instead, it is usually better to set more specific and limited permissions that are appropriate for the file or directory in question.

octal notation 和 symbolic notation

  • What’s the relation between symbolic notation and octal notation of chmod

  • In chmod, symbolic notation and octal notation are two different ways of specifying the access rights (permissions) for a file or directory.

    Symbolic notation uses letters and symbols to represent the permissions for the owner, group, and others. For example, u=rwx means that the owner has read, write, and execute permissions, while g=rx means that the group has read and execute permissions.

    Octal notation uses a combination of three digits to represent the same permissions. Each digit represents the permissions for the owner, group, and others, respectively. The digits are calculated by adding up the values for the permissions that are granted. For example, 7 means that the owner has read, write, and execute permissions (4 + 2 + 1), 5 means that the group has read and execute permissions (4 + 1), and 4 means that others have read permission only (4).

    Here is a table showing the correspondence between octal notation and symbolic notation:

    Octal notationSymbolic notation
    0
    1–x
    2-w-
    3-wx
    4r–
    5r-x
    6rw-
    7rwx

编译链接

  • how to complie and link .c files in ubuntu in one step or separate in two steps ?

    In Ubuntu, you can compile and link a C program in one step or in two separate steps using the gcc compiler.

    • 一步直接

      To compile and link a C program in one step, you can use the gcc command followed by the names of all the source files and any necessary libraries. For example, to compile and link a program called program with three source files, file1.c, file2.c, and file3.c, you can use the following command:

      gcc -o program file1.c file2.c file3.c -lm
      

      This will compile and link the source code files into an executable file called program.

      解释一下这里的-lm

      In the context of C programming, the -lm flag is used to tell the gcc compiler to link the math library when creating an executable file.

      The math library is a collection of functions that provide mathematical operations such as trigonometric functions(三角函数), exponential functions, and logarithmic(对数的) functions. These functions are declared in the math.h header file, and are usually implemented in a library file called libm.a or libm.so.

      To use the math library in a C program, you will need to include the math.h header file and link the math library when compiling and linking your program. To link the math library, you can use the -lm flag with the gcc compiler.

      For example:

      gcc -o program file.c -lm
      

      This will compile the file.c source code file and link it with the math library to create an executable file called program.

    • 分为两步

      Alternatively, you can compile the source code files into object files separately and then link them together in a separate step.

      To do this, you can use the gcc command with the -c flag to compile the source code files into object files, and then use the gcc command again with the -o flag to link the object files and create the executable file.

      For example:

      gcc -c file1.c file2.c file3.c
      gcc -o program file1.o file2.o file3.o -lm
      

      This will create object files for each of the source code files, and then link them together to create the program executable.

之前解决这三个心态要搞没了

crti.o 、 crt1.o

crti.o and crt1.o are object files that are part of the C runtime library. The C runtime library is a collection of functions and data structures that are used by C programs to perform various tasks, such as initializing variables, handling exceptions, and performing input/output operations.

crti.o and crt1.o are typically located in the /usr/lib or /usr/lib64 directories on most systems. They are required for linking C programs on many systems.

libgcc_s.so is a shared library file that is part of the GCC support library. The GCC support library is a collection of functions and data structures that are used by the GNU Compiler Collection (GCC) to perform various tasks, such as handling exceptions, implementing floating-point operations, and supporting language features.

libgcc_s.so is typically located in the /usr/lib or /usr/lib64 directories on most systems. It is required for linking programs compiled with GCC on many systems.

I hope this helps! Let me know if you have any questions or if you need further assistance.

libgcc_s.so

libgcc_s.so is a shared library that contains object code for the GNU Compiler Collection (GCC) support functions. These functions include low-level operations such as exception handling, thread-local storage, and atomic operations.

libgcc_s.so is typically used as a dependency of other shared libraries and executables that are compiled with GCC. It is often used to provide support for features that are not available in the standard system libraries, such as the C++ exception handling mechanism.

libgcc_s.so is usually located in a system-specific library directory, such as /usr/lib or /usr/local/lib on Linux systems. It is typically installed as part of the GCC package, and is automatically linked to programs that are compiled with GCC.

If you receive an error message that refers to libgcc_s.so, it may indicate that a shared library or executable that you are trying to run is missing a dependency or has a version mismatch. In this case, you may need to install or update the library or executable to resolve the issue.

ld

ld is the GNU Linker. It is a command-line tool that is used to link object files and libraries to create executable programs or shared libraries.

When you compile a program written in a high-level language such as C or C++, the compiler produces object files that contain machine code for the individual functions and data definitions in your program. These object files do not contain all of the information needed to create a standalone executable, as they are missing references to functions and data defined in system libraries or other object files.

The linker combines the object files and libraries into a single executable or shared library, resolving the references between the different object files and linking them together into a single cohesive(结成一个整体的) unit. The linker also adds metadata to the executable, such as the program’s entry point and any required runtime libraries, and can perform other tasks such as optimizing the program’s memory layout.

You can use the ld command to specify the object files and libraries that you want to link together, as well as any linker options that control the linking process. The linker produces an executable or shared library file as its output.

For example, to link a program written in C that consists of two object files main.o and foo.o, you might use a command like this:

ld main.o foo.o -o myprogram

This command would link the object files main.o and foo.o into an executable called myprogram.

ld --verbose

The ld command is the GNU Linker, a tool that is used to link object files and libraries into an executable program. The --verbose flag is an option that tells ld to print detailed information about the linking process.

When you use the ld command with the --verbose flag, it will print a list of the object files and libraries that are being linked, as well as the names of any undefined symbols (symbols that are referenced by the object files but not defined).

Here is an example of using the ld command with the --verbose flag:

ld --verbose -o program file1.o file2.o file3.o -lm

This will link the object files file1.o, file2.o, and file3.o and the math library (-lm) into an executable file called program, and will print detailed information about the linking process.

The --verbose flag can be useful for debugging linking issues or for understanding how ld is linking your object files and libraries.

ldconfig -p

ldconfig is a program that is used to configure the dynamic linker runtime bindings. It is typically used to create, update, and remove the necessary links and cache to the most recent shared libraries found in the directories specified in the /etc/ld.so.conf file and the default directories, such as /lib, /usr/lib, etc.

The -p option tells ldconfig to display the current cache of shared libraries. When you run ldconfig -p, it displays a list of shared libraries that are currently in the cache, along with their path, version, and dependencies.

Here is an example of the output of ldconfig -p:

libc.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libc.so.6
libz.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libz.so.1
libm.so.6 (libc6,x86-64) => /lib/x86_64-linux-gnu/libm.so.6
libpthread.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libpthread.so.0
libgcc_s.so.1 (libc6,x86-64) => /lib/x86_64-linux-gnu/libgcc_s.so.1
libc.so.6 (libc6) => /lib/i386-linux-gnu/libc.so.6
libz.so.1 (libc6) => /lib/i386-linux-gnu/libz.so.1
libm.so.6 (libc6) => /lib/i386-linux-gnu/libm.so.6
libpthread.so.0 (libc6) => /lib/i386-linux-gnu/libpthread.so.0
libgcc_s.so.1 (libc6) => /lib/i386-linux-gnu/libgcc_s.so.1

In this example, the output shows the shared libraries that are currently in the cache, along with their path, version, and dependencies. The libc6,x86-64 and libc6 entries indicate the version and dependencies of the shared library.

You can use ldconfig -p to check which shared libraries are currently in the cache and troubleshoot issues with shared library dependencies.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/116864.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

SegeX Progress:MFC通用进度条

----哆啦刘小洋 原创&#xff0c;转载需说明出处 MFC高级通用进度条-目录1 简介2 进度条实现基本原理3 使用方法3 .1 简单情况3.2 两个前后独立的进度条3.3 实际应用的一般情况3.4 带子进度条4 其他4.1 使用限制4.2 其他全局宏&#xff08;函数&#xff09;4.3 当前进度条设置1…

技术开发107

技术开发107 业务内容&#xff1a; 汽车音响等汽车电子部件试制、电子设备部件试制、精密钣金试制精密钣金试制 公司简介&#xff1a; 代表&#xff1a;中山尚美 成立时间&#xff1a;1950年6月 资本金&#xff1a;1000万日元 员工数&#xff1a;15名 资格认证&#xff…

数智为线,经纬中国:新华三勾勒出的山河锦绣

刺绣&#xff0c;是中华民族源远流长的技艺美术。早在《尚书》中&#xff0c;就记载了章服制度“衣画而裳绣”。而刺绣之美之所以能够传承千年&#xff0c;形成中国审美的一张名片&#xff0c;就是因为传统的染色技艺不够精细&#xff0c;颜色常常浮在布匹表面&#xff0c;但刺…

【卫朋】营销技能:营销4P之外,还有这些经典理论

一提到市场营销&#xff0c;很多人都可能会联想到经典的营销4P理论&#xff0c;但你可能不知道的是&#xff0c;4P理论只是“4字营销理论家族”中的一员。 市场营销“4字家族”中的4P、4R、4C理论构成了市场营销的基础部分。 它们诞生于特殊的环境和年代&#xff0c;为当时的企…

Redis原理篇—内存回收

Redis原理篇—内存回收 笔记整理自 b站_黑马程序员Redis入门到实战教程 内存过期策略-过期key处理 Redis 之所以性能强&#xff0c;最主要的原因就是基于内存存储。然而单节点的 Redis 其内存大小不宜过大&#xff0c;会影响持久化或主从同步性能。 我们可以通过修改配置文件…

再学C语言16:表达式和语句

语句组成了C的基本程序的步骤&#xff0c;大多数语句由表达式构造而成 一、表达式 表达式&#xff08;expression&#xff09;由运算符和操作数组合构成 操作数是运算符操作的对象&#xff0c;可以是常量、变量或二者的组合 C的一个重要属性&#xff1a;每一个C表达式都有一…

Python 基础教程(1)——翻转字符串、集合运算、字符串、列表、元组、字典、数据类型转换、Python推导式、Python运算符、Python 数字类型转换、字符串

1.翻转字符串 def reverseWords(input):# 通过空格将字符串分隔符&#xff0c;把各个单词分隔为列表inputWords input.split(" ")# 翻转字符串# 假设列表 list [1,2,3,4], # list[0]1, list[1]2 &#xff0c;而 -1 表示最后一个元素 list[-1]4 ( 与 list[3]4 一样…

【C++进阶】特殊类设计

&#x1f387;C学习历程&#xff1a;入门 博客主页&#xff1a;一起去看日落吗持续分享博主的C学习历程博主的能力有限&#xff0c;出现错误希望大家不吝赐教分享给大家一句我很喜欢的话&#xff1a; 也许你现在做的事情&#xff0c;暂时看不到成果&#xff0c;但不要忘记&…

vue书写一个uni-app小程序

在本次文章中我来大致向大家介绍一下如何使用Hbuilder X来编写一个uni-app的小程序的项目&#xff0c;在此我只说编写的方法与方向&#xff0c;具体的操作留给大家去亲自实操哦。 1.起步&#xff08;创建一个uni-app框架&#xff09;&#xff1a; 首先&#xff0c;我们需要把…

低代码破解了软件开发“不可能三角”?我做了个测评...

老读者知道&#xff0c;K哥写了10几年代码&#xff0c;后来转做技术管理&#xff0c;现在是上市公司的技术高管。在我们软件行业有一条铁律&#xff1a;长周期、大规模的软件研发过程当中&#xff0c;想要维持良好的运作&#xff0c;需要解决&#xff1a;成本、效能、质量。而且…

Doris-查询(三)

目录1、查询设置1.1、增大内存1.2、修改超时时间1.3、查询重试和高可用1.3.1 代码方式1.3.2 JDBC Connector1.3.3 ProxySQL 方式2、简单查询3、Join查询3.1 Broadcast Join3.2 Shuffle Join&#xff08;Partitioned Join&#xff09;3.3 Colocation Join3.3.1 原理3.3.2 使用3.…

数字孪生电力3D可视化管控平台

当前&#xff0c;新一轮科技革命和产业变革加速演进&#xff0c;物联网、大数据、云计算、人工智能、5G等新一代信息技术快速发展。在众多技术手段中&#xff0c;数字孪生技术以虚实结合为主&#xff0c;架起虚拟世界与现实世界之间沟通的桥梁&#xff0c;为人们提供了更加便捷…

分享5款可以录屏的软件,录屏幕视频软件,亲测好用

很多小伙伴都会使用电脑来作为自己办公、娱乐、学习生活的工具。在电脑上安装录屏软件&#xff0c;可以轻松的协助我们进行网课录制、会议录制、影剧片段录制等。网络上的录屏软件有很多&#xff0c;今天小编分享5款亲测好用的录屏软件&#xff0c;一起来看看吧。 可以录屏的软…

数据结构进阶 二叉搜索树

作者&#xff1a;小萌新 专栏&#xff1a;数据结构进阶 作者简介&#xff1a;大二学生 希望能和大家一起进步&#xff01; 本篇博客简介&#xff1a;介绍二叉搜索树并且模拟实现之 二叉搜索树二叉搜索树的概念节点类二叉搜索树类私有成员构造函数拷贝构造函数赋值运算符重载函数…

若想学 HTML,应从何入手?

前言 个人信息&#xff1a; 大三 工商管理 逻辑算清晰 无编程基础 想学网页设计&#xff0c;打算从HTML开始 。 下面是问题&#xff1a; 需要先学一些更基础的语言&#xff08;如C之类的&#xff09;吗&#xff1f;有何建议&#xff1a; &#xff08;1&#xff09;看哪些书、泡…

无忧·企业邮筒功能介绍

应用介绍 企业邮筒&#xff0c;基于B/S模式的邮件客户端&#xff0c;采用JVS的统一用户体系&#xff0c;作为JVS的协同办公的应用之一。 产品特点 私有化部署、支持多邮件账户、将多个邮件客户端统一为web操作、 软件架构 软件架构说明&#xff0c;JVS-mailbox是作为JVS基…

服装实体店运营需要的所有软件,合集在此!(建议收藏)实体店运营 实体店运营干货 实体店运营全流程所需系统推荐

随着信息化普及程度越来越高&#xff0c;各行各业的运转速度都在加快&#xff0c;做生意的老板们也开始发现&#xff0c;单靠以前的人工管理已经完全不够用了。 尤其是服装实体店&#xff0c;款式分类多&#xff0c;库存又容易挤压&#xff0c;更加需要有科学的手段去管控日常的…

MyBatis学习 | 缓存机制

文章目录一、一级缓存1.1 简介1.2 一级缓存的失效情况二、二级缓存2.1 简介2.2 二级缓存的使用学习地址&#x1f517; https://www.bilibili.com/video/BV1mW411M737https://www.bilibili.com/video/BV1NE411Q7Nx官网文档 一、一级缓存 1.1 简介 &#x1f4ac;概述&#xff1…

Spring与SpringBoot

目录 前言 1、Spring能做什么 1.1、Spring的能力 1.2、Spring的生态 1.3、Spring5重大升级 1.3.1、响应式编程 1.3.2、内部源码设计 2、为什么用SpringBoot 2.1、SpringBoot优点 2.2、SpringBoot缺点 3、时代背景 3.1、微服务 3.2、分布式 分布式的困难 分布式的…

迪文DGUS智能屏如何轻松实现3D动画

三维立体的视觉效果已经被广泛应用于人机交互中&#xff0c;三维图形逼真的显示效果往往可以更加直接的传递出视觉信息&#xff0c;减少用户的信息解读门槛。 传统的三维立体静态、动态画面的显示往往对于 GPU 的图像处理性能、显示带宽有较高要求&#xff0c;GPU 需要完成图形…