Progress control of UNIX advanced programming

Source: Internet
Author: User

Process Control

PS aux
PS AXJ
PS AXF
PS AXM

I. Process identifiers
pid_t---->long int
Unique identity of the process

0 calling process (kernel)
1init process (user-state ancestor process for all processes)

Getpid (2);
Getppid (2);

Status of the process
s interruptible sleep state
R Run State
D Non-disruptive sleep state
T stop State
x termination state
Z Zombie State
Process priority
S conversation leader
L Multithreading
< high-priority
N Low-priority
+ in the foreground process group

Two. Fork (2)
Differences between parent and child processes:
<1>pid
<2>ppid
<3> Record Lock
<4> Resource usage and process time zeroing
<5> Pending signals
<6> Pending Alarms
<7>fork return value

Fork () Create child process
<1> cannot guarantee which process will run first
<2> using Copy-on-write
<3> returns the child process ID in the parent process, returning 0 in the child process

Vfork () Creating child processes
<1> ensure child processes run first
<2> Sharing parent process data segments and stacks
<3> terminating the process with _exit (2) or _exit (2)

Orphan process
Zombie Process

Three. Wait (2) and waitpid (2);

Wait (&status); = = Waitpid ( -1, &status, 0);

Four. EXEC (3);
Execl ();
Execv ();
EXECLP ();
EXECVP ();
Execle ();

Five.
Process relationships
1. Session: One or more process groups
GetSID (2);
Setsid (2);

2. Process group: One or more processes are composed of
GETPGRP (2);
Getpgid (2);
Setpgid (2);

Daemon process
Leader Pgid = = PID of the <1> process group
<2> session leader SID = = PID
<3> Disengagement Control Terminal

To create a daemon step:
<1>umask (0);
<2>chdir ("/");
<3> Close 0,1,2
<4>child-->setsid ();

Writing of log logs
Openlog ();
Syslog ();
Closelog ();

Daemon (3);

Six. Competitive conditions
Parent--->wait ();
Child--->getppid () = = 1

Seven. System (3)
Fork ()-->exec ("/bin/sh", "sh", "-C", "Ls-l", NULL)

Eight. Change the user ID and group ID
Actual User ID
Valid User id: Verify file Permissions U+s
Save Settings User ID

Setuid (2);
Getuid (2);
Geteuid (2);

Nine. Process time
Times (2);

Real: >= Sys+user;
Sys
User

10. Interpreter files
Know

Progress control of UNIX advanced programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.