Search     or:     and:
 LINUX 
 Language 
 Kernel 
 Package 
 Book 
 Test 
 OS 
 Forum 
 iakovlev.org 
      Languages 
      Kernels 
      Packages 
      Books 
      Tests 
      OS 
      Forum 
      Математика 
NEWS
Последние статьи :
  Rust 07.11   
  Go 25.12   
  EXT4 10.11   
  FS benchmark 15.09   
  Сетунь 23.07   
  Trees 25.06   
  Apache 03.02   
  SQL 30.07   
  JFS 10.06   
  B-trees 01.06   
 
TOP 20
 Robbins 6...549 
 Go Web ...305 
 CPAN-> FAQ...230 
 Robbins...214 
 Python...179 
 Trees...166 
 Secure Programming for Li...158 
 Go...138 
 Kernel Notes...132 
 Linux Inline Assembly...131 
 C++ Templates 2...118 
 Autoconf...111 
 M.Pilgrim->Часть 2...94 
 Stewens -> IPC 6...93 
 Intel 386...90 
 M.Pilgrim->Часть 3...89 
 Httpd-> История Ap...87 
 Robbins 5...85 
 Cluster 4...81 
 Rubni-Corbet -> Глав...79 
 
  01.10.2019 : 2795711 посещений 

www.iakovlev.org
#include < errno.h>
#include < signal.h>
#include < sys/wait.h>

#include < linux/sched.h>
#include < linux/kernel.h>
#include < linux/tty.h>
#include < asm/segment.h>

int sys_pause(void);
int sys_close(int fd);

void release(struct task_struct * p)
{
	int i;

	if (!p)
		return;
	for (i=1 ; i32)
		return;
	if (priv ||
		current->uid==p->uid ||
		current->euid==p->uid ||
		current->uid==p->euid ||
		current->euid==p->euid)
		p->signal |= (1<<(sig-1));
}

void do_kill(long pid,long sig,int priv)
{
	struct task_struct **p = NR_TASKS + task;

	if (!pid) while (--p > &FIRST_TASK) {
		if (*p && (*p)->pgrp == current->pid)
			send_sig(sig,*p,priv);
	} else if (pid>0) while (--p > &FIRST_TASK) {
		if (*p && (*p)->pid == pid)
			send_sig(sig,*p,priv);
	} else if (pid == -1) while (--p > &FIRST_TASK)
		send_sig(sig,*p,priv);
	else while (--p > &FIRST_TASK)
		if (*p && (*p)->pgrp == -pid)
			send_sig(sig,*p,priv);
}

int sys_kill(int pid,int sig)
{
	do_kill(pid,sig,!(current->uid || current->euid));
	return 0;
}

int do_exit(long code)
{
	int i;

	free_page_tables(get_base(current->ldt[1]),get_limit(0x0f));
	free_page_tables(get_base(current->ldt[2]),get_limit(0x17));
	for (i=0 ; ifather == current->pid)
			task[i]->father = 0;
	for (i=0 ; ifilp[i])
			sys_close(i);
	iput(current->pwd);
	current->pwd=NULL;
	iput(current->root);
	current->root=NULL;
	if (current->leader && current->tty >= 0)
		tty_table[current->tty].pgrp = 0;
	if (last_task_used_math == current)
		last_task_used_math = NULL;
	if (current->father) {
		current->state = TASK_ZOMBIE;
		do_kill(current->father,SIGCHLD,1);
		current->exit_code = code;
	} else
		release(current);
	schedule();
	return (-1);	/* just to suppress warnings */
}

int sys_exit(int error_code)
{
	return do_exit((error_code&0xff)<<8);
}

int sys_waitpid(pid_t pid,int * stat_addr, int options)
{
	int flag=0;
	struct task_struct ** p;

	verify_area(stat_addr,4);
repeat:
	for(p = &LAST_TASK ; p > &FIRST_TASK ; --p)
		if (*p && *p != current &&
		   (pid==-1 || (*p)->pid==pid ||
		   (pid==0 && (*p)->pgrp==current->pgrp) ||
		   (pid<0 && (*p)->pgrp==-pid)))
			if ((*p)->father == current->pid) {
				flag=1;
				if ((*p)->state==TASK_ZOMBIE) {
					put_fs_long((*p)->exit_code,
						(unsigned long *) stat_addr);
					current->cutime += (*p)->utime;
					current->cstime += (*p)->stime;
					flag = (*p)->pid;
					release(*p);
					return flag;
				}
			}
	if (flag) {
		if (options & WNOHANG)
			return 0;
		sys_pause();
		if (!(current->signal &= ~(1<<(SIGCHLD-1))))
			goto repeat;
		else
			return -EINTR;
	}
	return -ECHILD;
}