A preliminary understanding of the basic functions of the Linux operating system

 

 

  1. Fork() function: execute twice and return once. After the fork function is executed, if the new process is created successfully, two processes will appear, one is the child process and the other is the parent process. In the child process, the fork function returns 0. In the parent process, fork returns the process ID of the newly created child process. We can determine whether the current process is a child process or a parent process by the value returned by fork.
    while((p1=fork())==-1); //如果子进程创建失败,则返回-1,while循环条件为==-1为真,重新执行while()循环,相当于不断重复创建子进程一直到创建成功为止

     

  2. wait() function: Once the parent process calls wait, it immediately blocks itself. Wait automatically analyzes whether a child process of the current process has exited. If it finds such a child process that has become a zombie, wait will collect this Information about the child process and return it after it is completely destroyed; if such a child process is not found, wait will be blocked here until one appears.
  3. signal() function: signal signal function, the first parameter represents the signal value (SIGHUP) that needs to be processed, and the second parameter is the processing function or a representation. Here, SIG_IGN means ignoring the registered signal of SIGHUP.
    #供学习参考的代码片段
    
    signal(SIGINT,SIG_IGN);//忽略键盘输入的 Ctrl+C
    
    signal(16,Int1); //只要收到信号16,则执行Int1()函数
  4. kill() function: send a signal to the relevant process;
    void IntDelete()
    
    {
    
    kill(pid1,16); //向进程 pid1 发送信号16
    
    kill(pid2,17); //同上
    
    }
  5. Pause() function: The current process is in a waiting state and cannot resume execution until a signal is received.
  6. lockf(1,1,0) function: lock the standard output device, lockf(1,0,0): unlock the standard output device.
    lockf(1,1,0); //锁定标准输出设备
    
    for(i=0;i<500;i++)
    
        printf("son %d\n",i);
    
    lockf(1,0,0); //解锁标准输出设备
  7. sleep() function: self-blocking
    sleep(5); //自我阻塞五妙

     

Guess you like

Origin blog.csdn.net/geeksoarsky/article/details/89681177
Recommended