Hello I have a little problem.
I have a server and a client, the client stops the server,then it waits for
5,and then it sends the signal SIGINT to the server.
The server stops ( after client sends SIGSTOP) and then restarts ( after
client sends SIGCONT ) ,but after the server restarts and it doesn't execute
the switch and so it re-stops again ,but the client hasn't sends the SIGSTOP
signal.
Look at the source, first launch the server in bk and then launch the client
,and look the output.I have tried a lot of solutions but without
success.Where is the mistake?PLZ help me.
Thanks
Giuseppe
the source,but first you have to create a named file : chiave ,it is the key
for the ftok call.
server --------------------------------------------------------------
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#define SIZE 2
int shm_id,shm_id_lista;
int
main(void)
{
pid_t *process;
key_t mykey,mykey_lista,mykey_sem_bin;
pid_t pid_agenzia;
char scelta[SIZE];
int numero_sel;
int num;
mykey = ftok("./chiave",'a');
if ( mykey == - 1 )
{
perror("ERRORE - FTOK NON HA GENERATO LA CHIAVE PER IL PID ");
exit(1);
shm_id = shmget(mykey,sizeof(pid_t),IPC_CREAT | SHM_R | SHM_W);Quote:}
if (shm_id == -1)
{
perror("ERRORE - MEMORIA CONDIVISA NON CREATA ");
exit(1);
process=(int *)shmat(shm_id,0,0);Quote:}
if ((int)process == -1)
{
perror("ERRORE - MEMORIA CONDIVISA NON COLLEGATA ");
exit(1);
*process = getpid();Quote:}
write(1,"\n sono il server",16);
// raise(SIGSTOP);
sleep(10);
write(1,"\n server restarted\n",20);
/*write(1,"\nserver restarted",19);
*/
while (num != 4)
//do
{
write(1,"num=",4);
read(STDIN_FILENO,&num,1);
// numero_sel = getc(stdin);
// scelta = getc(stdin);
// scanf("%c",&scelta);
//scelta = getchar();
switch(num)
{
case '0' :
printf("\n caso 0");
break;
case '1' :
printf("\n caso 1");
break;
case '2' :
printf("\n caso 2");
break;
case '3' :
printf("\n caso 3");
break;
// while (num == '1');Quote:}
}
client ------------------------------------------------------------------Quote:}
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include <sys/stat.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
int shm_id,shm_id_lista;
int
main(void)
{
pid_t *process;
key_t mykey,mykey_lista,mykey_sem_bin;
pid_t pid_agenzia,pid_server;
mykey = ftok("./chiave",'a');
if ( mykey == - 1 )
{
perror("ERRORE - FTOK NON HA GENERATO LA CHIAVE PER IL PID ");
exit(1);
shm_id = shmget(mykey,sizeof(pid_t),IPC_CREAT | SHM_R | SHM_W);Quote:}
if (shm_id == -1)
{
perror("ERRORE - MEMORIA CONDIVISA NON CREATA ");
exit(1);
process=(int *)shmat(shm_id,0,0);Quote:}
if ((int)process == -1)
{
perror("ERRORE - MEMORIA CONDIVISA NON COLLEGATA ");
exit(1);
pid_server = *process;Quote:}
kill(pid_server,SIGSTOP);
sleep(5);
//pid_server = *process;
kill(pid_server,SIGCONT);
Quote:}