raider Posted January 6, 2016 at 02:57 PM Report Share #591486 Posted January 6, 2016 at 02:57 PM (edited) Será que alguém me conseguirá ajudar a responder à seguinte questão: Quantas vezes Imprime a mensagem SISTEMAS OPERATIVOS, no seguinte programa e porquê? Código: for(i=0;i<3;i++) { pid = fork(); if(pid ==0) pid = fork(); if(pid > 0) printf("SISTEMAS OPERATIVOS"); } Edited January 6, 2016 at 09:29 PM by pwseo tags code, syntax highlight. Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted January 6, 2016 at 03:10 PM Report Share #591488 Posted January 6, 2016 at 03:10 PM (edited) isto é uma questão muito específica, tens como confirmar que não estás a fazer um exame ? dica : - o thread principal corre o ciclo 3 vezes > escreve a mensagem 3 vezes > cria 3 thread - cada thread filho directo do thread principal executa o ciclo 2 vezes (i = 1 até 3) > escreve a mensagem 2 vezes > cria 2 threads ... etc, etc ... Edited January 6, 2016 at 03:25 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
raider Posted January 6, 2016 at 04:05 PM Author Report Share #591492 Posted January 6, 2016 at 04:05 PM (edited) Eu compilei o programa e ele imprime 26 vezes a mensagem "SISTEMAS OPERATIVOS" E se executar o mesmo programa mas com um execlp(). Apenas irá imprimir uma vez certo, pois o comando execlp(), apagará tudo o que está antes de ser chamado??? for(i=0;i<3;i++) { pid = fork(); if(pid ==0) pid = fork(); if(pid > 0) execlp("SO", "SO",0); } Edited January 6, 2016 at 09:30 PM by pwseo tags code, syntax highlight. Link to comment Share on other sites More sharing options...
HappyHippyHippo Posted January 6, 2016 at 04:40 PM Report Share #591495 Posted January 6, 2016 at 04:40 PM ?? o que acabaste de dizer não faz sentido para mais informação, existe a documentação : http://linux.die.net/man/3/execlp IRC : sim, é algo que ainda existe >> #p@p Portugol Plus Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now