Universidad de Costa RicaEscuela de Ciencias de la Computación e InformáticaCI-0122 Sistemas operativosEjemplos |
|
| CI0122 / Ejemplos / fork | |
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#define MAX_COUNT 50
#define BUF_SIZE 100
int main(void)
{
pid_t pid;
int i;
char buf[BUF_SIZE];
fork();
pid = getpid();
for (i = 1; i <= MAX_COUNT; i++) {
sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
write(1, buf, strlen(buf));
}
}