Deutsch   English   Français   Italiano  
<81f7a286-e4ae-495c-9527-d15d720575a1n@googlegroups.com>

View for Bookmarking (what is this?)
Look up another Usenet article

X-Received: by 2002:a05:622a:1a20:b0:3f0:abe7:24a2 with SMTP id f32-20020a05622a1a2000b003f0abe724a2mr5509263qtb.10.1682975558793;
        Mon, 01 May 2023 14:12:38 -0700 (PDT)
X-Received: by 2002:a81:d303:0:b0:54f:646d:19c8 with SMTP id
 y3-20020a81d303000000b0054f646d19c8mr9259591ywi.3.1682975558477; Mon, 01 May
 2023 14:12:38 -0700 (PDT)
Path: ...!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: fr.comp.sys.atari
Date: Mon, 1 May 2023 14:12:38 -0700 (PDT)
In-Reply-To: <M8e3pvNp4cbQ8PseiWxbN_ORsQs@jntp>
Injection-Info: google-groups.googlegroups.com; posting-host=90.2.151.231; posting-account=jGtioQoAAAAtlyZrlcSNYAx7TsxqJls_
NNTP-Posting-Host: 90.2.151.231
References: <M8e3pvNp4cbQ8PseiWxbN_ORsQs@jntp>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <81f7a286-e4ae-495c-9527-d15d720575a1n@googlegroups.com>
Subject: =?UTF-8?Q?Re=3A_fork=28=29_sous_Multitos_question_=C3=A0_Fran=C3=A7ois?=
From: Francois LE COAT <lecoat@gmail.com>
Injection-Date: Mon, 01 May 2023 21:12:38 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Bytes: 3128
Lines: 73

Salut,

OL =C3=A9crit :
> Fran=C3=A7ois tu es passionnant, tu vas pouvoir m'expliquer un truc a moi=
,=20
> j'esp=C3=A8re que tu ne vas pas louper une occasion!
>=20
>=20
> Comme tu nous a dit que tu avais utilis=C3=A9 ton Falcon sous Multitos po=
ur=20
> faire des TD et montrer l'utilisation de fork(), je veux bien te croire=
=20
> mais j'aimerais comprendre ce que tu voulais montrer, qu'est ce que ton=
=20
> TD =C3=A9tait sens=C3=A9 montrer? Qu'est ce qu'il faisait?
>=20
> OL

Tiens, je t'envoie un exemple simple ...

/*
 * Programme who|wc : compte le nombre d'utilisateurs
 */

#include <stdio.h>
#include <unistd.h>

void main(void);

int p[2]; /* Identificateurs des canaux de communication */

void main()
	{
	int pid; /* Identificateur des processus */

 	if(pipe(p)!=3D0)
 		{
		perror("\nCreation d'un canal impossible\n");
		exit(1);
		}

	pid=3Dfork();
 	if(pid=3D=3D0)
 		{ /* Processus PERE : Il execute "who" */
		close(1); /* Fermeture de la sortie standard */
		dup(p[1]) /* Duplique la sortie du pere en sortie standard */
		close(p[0]); /* L'entree du pere ne sert plus a rien */
		close(p[1]); /* La sortie non plus */
		execlp("who","who",NULL);
		}
	else if(pid<0)
	 	{
		perror("\nFork impossible\n");
		}
/* Processus Fils : il execute a nouveau un fork */
	pid=3Dfork();
 	if(pid=3D=3D0)
 		{ /* Processus PERE : Il execute "wc" */
		close(0); /* Fermeture de l'entree standard */
		dup(p[0]) /* Duplique l'entree du pere en entree standard */
		close(p[0]); /* L'entree du pere ne sert plus a rien */
		close(p[1]); /* La sortie non plus */
		execlp("wc","wc",NULL);
		}
	else if(pid<0)
	 	{
		perror("\nFork impossible\n");
		}
/* Processus Fils : Attend la fin des deux processus */
	close(p[0]); /* L'entree du fils ne sert plus a rien */
	close(p[1]); /* La sortie non plus */
	while(wait()>=3D0);
 	exit(0);
	}