-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpcb.c
1266 lines (1182 loc) · 41.2 KB
/
pcb.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*Prototipos de funciones*/
pcb* create_pcb_mem();
int next_pcb(pcb **aux,pcb *f);
int prev_pcb(pcb **aux,pcb *r);
int next_pcbG(pcb **aux,pcb *f);
int prev_pcbG(pcb **aux,pcb *f);
int next_pcbU(pcb **aux,pcb *f);
int prev_pcbU(pcb **aux,pcb *f);
int next_pcb_states(pcb **aux,pcb *f);
int prev_pcb_states(pcb **aux,pcb *f);
void print_pcbInfo(pcb *aux);
pcb* find_pcb(int pid, pcb *front);
int can_create(groups *gFront, users *uFront);
int set_pid(pcb *front);
void create_process(int cpp, pcbCtrl *ctrl, pcbStates *states, groupsCtrl *ctrlG, usersCtrl *ctrlU);
int execute(int t,pcb *exec);
void rr(pcbStates *states, pcbCtrl *ctrl, int quantum, int *totalTime);
void show_pcb(pcbCtrl *ctrl);
void show_everything(pcbCtrl *ctrl, pcbStates *states, groupsCtrl *ctrlG, usersCtrl *ctrlU);
int del_pcss(pcbCtrl *ctrl, pcbStates *states);
void del_pcss_reaper(pcbCtrl *ctrl, pcbStates *states, pcb *elm);
void state_change(pcbCtrl *ctrl, pcbStates *states);
void changer(pcbCtrl *lista, pcb *elm,pcbStates *states);
void del_pcss_reaper(pcbCtrl *ctrl, pcbStates *states, pcb *elm);
int show_pcb_sleeping(pcbStates *states);
void del_option(pcbCtrl *ctrl, pcbStates *states, groupsCtrl *gp, usersCtrl *us);
/*Crea la memoria para alojar un proceso*/
pcb* create_pcb_mem()
{
pcb *temp;
temp = (pcb *)malloc(sizeof(pcb));
temp->sense = (pcbMov *)malloc(sizeof(pcbMov *));
temp->stateSense = (pcbMov *)malloc(sizeof(pcbMov *));
temp->groupSense = (pcbMov *)malloc(sizeof(pcbMov *));
temp->userSense = (pcbMov *)malloc(sizeof(pcbMov *));
temp->group = (groups *)malloc(sizeof(groups *));
temp->user = (users *)malloc(sizeof(users *));
temp->sense->next = NULL;
temp->sense->prev = NULL;
temp->stateSense->next = NULL;
temp->stateSense->prev = NULL;
temp->groupSense->next = NULL;
temp->groupSense->prev = NULL;
temp->userSense->next = NULL;
temp->userSense->prev = NULL;
strcpy(temp->group->n," ");
strcpy(temp->user->n," ");
temp->first_exe = 0;
temp->user->uid = -1;
temp->group->gid = -1;
temp->pid = -1;
temp->cp = -1;
temp->tim[0] = -1;
temp->tim[1] = -1;
temp->tim[2] = -1;
temp->state = -1;
temp->gen = 0;
return temp;//
}
/*Desplaza al siguiente proceso en una determinada lista*/
int next_pcb(pcb **aux,pcb *f)
{
int b = 0;
if( ((**aux).sense->next == NULL) || ((**aux).sense->next == f))
b = FAIL;
else
*aux = (**aux).sense->next; //Desplazamiento al siguiente elemento
return b;
}
/*Desplaza al proceso anterior en una determinada lista*/
int prev_pcb(pcb **aux,pcb *r)
{
int b = 0;
if((**aux).sense->prev == r)
b = FAIL;
else
*aux = (**aux).sense->prev; //Desplazamiento al siguiente elemento
return b;
}
/*Desplaza al siguiente proceso en una determinada lista*/
int next_pcb_states(pcb **aux,pcb *f)
{
int b = 0;
if( ((**aux).stateSense->next == NULL) || ((**aux).stateSense->next == f))
b = FAIL;
else
*aux = (**aux).stateSense->next; //Desplazamiento al siguiente elemento
return b;
}
int prev_pcb_states(pcb **aux,pcb *f)
{
int b = 0;
if( ((**aux).stateSense->prev == NULL) || ((**aux).stateSense->prev == f))
b = FAIL;
else
*aux = (**aux).stateSense->prev; //Desplazamiento al siguiente elemento
return b;
}
/*Desplaza al siguiente proceso realacionado a cierto grupo*/
int next_pcbG(pcb **aux,pcb *f)
{
int b = 0;
if( ((**aux).groupSense->next == NULL) || ((**aux).groupSense->next == f))
b = FAIL;
else
*aux = (**aux).groupSense->next; //Desplazamiento al siguiente elemento
return b;
}
/*Desplaza al anterior proceso realacionado a cierto grupo*/
int prev_pcbG(pcb **aux,pcb *f)
{
int b = 0;
if( ((**aux).groupSense->prev == NULL) || ((**aux).groupSense->prev == f))
b = FAIL;
else
*aux = (**aux).groupSense->prev; //Desplazamiento al siguiente elemento
return b;
}
/*Desplaza al siguiente proceso relacionado a cierto usuario*/
int next_pcbU(pcb **aux,pcb *f)
{
int b = 0;
if( ((**aux).userSense->next == NULL) || ((**aux).userSense->next == f))
b = FAIL;
else
*aux = (**aux).userSense->next; //Desplazamiento al siguiente elemento
return b;
}
/*Desplaza al anterior proceso relacionado a cierto usuario*/
int prev_pcbU(pcb **aux,pcb *f)
{
int b = 0;
if( ((**aux).userSense->prev == NULL) || ((**aux).userSense->prev == f))
b = FAIL;
else
*aux = (**aux).userSense->prev; //Desplazamiento al siguiente elemento
return b;
}
/*Comprueba si hay usuarios y grupos creados*/
int can_create(groups *gFront, users *uFront)
{
int r = 0;
if(gFront == NULL)
{
r = FAIL;
printf("%s.\n","No se han creado grupos");
if(uFront == NULL)
printf("%s.\n","No se han creado usuarios");
}
else
{
if(uFront == NULL)
{
r =FAIL;
printf("%s.\n","No se han creado usuarios");
}
}
return r;
}
/*Encuentra un proceso*/
pcb* find_pcb(int pid, pcb *front)
{
pcb *chosen,*aux = front;
chosen = NULL;
do
{
if(pid == aux->pid)
{
chosen = aux;
break;
}
}while(next_pcb(&aux,front) != FAIL);
return chosen;
}
/*Evalua si el id de un proceso ha sido repetido y de ser
asi pregunta por otro o cancela la creacion del proceso*/
int set_pid(pcb *front)
{
int pid,flag = 0;
pcb *f = front;
if(front == NULL)
pid = set_int("el id del nuevo proceso",0);
else
{
pid = set_int("el id del nuevo proceso",0);
do
{
if(pid == f->pid)
{
flag = FAIL;
break;
}
}while(next_pcb(&f,front) != FAIL);
if(flag == FAIL)
{
printf("%s\n",REP_FAIL);
if(cancel("creacion del proceso") == 0)
pid = set_pid(front);
else
pid = FAIL;
}
}
return pid;
}
/**/
/*Crea un proceso, lo encola en la tabla de control de procesos conforme a
su momento de llegada y en la cola de listos
Se verifica que el id de proceso sea positivo y que
el grupo y usuario solicitado existan, de no hacerlo
se pregunta si se desea cancelar la operacion
*/
void create_process(int cpp,pcbCtrl *ctrl, pcbStates *states, groupsCtrl *ctrlG, usersCtrl *ctrlU)
{
int p[2];
groups *g;
users *u;
if(can_create(ctrlG->front,ctrlU->front) != FAIL)
{
if((p[0] = set_pid(ctrl->front)) > 0)
{
if((p[1] = set_int("la duracion del proceso",0)) > 0)
{
if(set_group(&g,ctrlG) > 0)
{
if(set_user(&u,ctrlU) > 0)
{
if(ctrl->front == NULL)//se verifica si hay procesos creados anteriormente
{
ctrl->front = create_pcb_mem();//se asigna la memoria para el proceso
if(ctrl->front != NULL)
{
/*Asignacion de los campos al nuevo proceso*/
printf("\nAsignando informacion al proceso...\n");
ctrl->front->cp = cpp;
ctrl->front->state = ID_LIS;
ctrl->front->pid = p[0];
ctrl->front->tim[0] = p[1];
ctrl->front->tim[1] = p[1];
ctrl->front->tim[2] = 0;
ctrl->front->gen = -1;
ctrl->front->user = u;
ctrl->front->group = g;
/*asignación del proceso a la lista de
procesos del grupo correspondiente*/
printf("Ligando proceso con su grupo...\n");
g->pcbG->front = ctrl->front;
g->pcbG->rear = g->pcbG->front;
g->pcbG->rear->groupSense->prev = g->pcbG->front;
g->pcbG->front->groupSense->prev = g->pcbG->rear;
g->pcbG->front->groupSense->next = g->pcbG->rear;
g->pcbG->rear->groupSense->next = g->pcbG->front;
/*asignación del proceso a la lista de
procesos del usuario correspondiente*/
printf("Ligando proceso con su usuario...\n");
u->pcbU->front = ctrl->front;
u->pcbU->rear = u->pcbU->front;
u->pcbU->rear->userSense->prev = u->pcbU->front;
u->pcbU->front->userSense->prev = u->pcbU->rear;
u->pcbU->front->userSense->next = u->pcbU->rear;
u->pcbU->rear->userSense->next = u->pcbU->front;
/*Se hace circular la lista que controla la pcb*/
ctrl->rear = ctrl->front; //Igualamos el frente y el fondo
ctrl->rear->sense->next = ctrl->front;
ctrl->rear->sense->prev = ctrl->front;
ctrl->front->sense->prev = ctrl->rear;
ctrl->front->sense->next = ctrl->rear;
/*Asignamos la lista de ejecucion */
printf("Encolando elemento a la lista de ejecucion...\n");
states->readys->front = ctrl->front;
states->readys->rear = states->readys->front;
states->readys->rear->stateSense->next = states->readys->front;
states->readys->rear->stateSense->prev = states->readys->front;
states->readys->front->sense->prev = states->readys->rear;
states->readys->front->stateSense->next = states->readys->rear;
printf("Proceso creado.\n");
}
else
printf("%s\n",MEM_FAIL);
}
else
{
ctrl->rear->sense->next = create_pcb_mem();//se asigna a memoria para el proceso
if(ctrl->rear->sense->next != NULL)//se verifica la creacion de la memoria
{
ctrl->rear->sense->next->sense->prev = ctrl->rear;
ctrl->rear = ctrl->rear->sense->next;
ctrl->rear->sense->next = ctrl->front;
ctrl->front->sense->prev = ctrl->rear;
printf("\nAsignando informacion al proceso...\n");
ctrl->rear->cp = cpp;
ctrl->rear->state = ID_LIS;
ctrl->rear->pid = p[0];
ctrl->rear->tim[0] = p[1];
ctrl->rear->tim[1] = p[1];
ctrl->rear->tim[2] = 0;
ctrl->rear->gen = 1;
ctrl->rear->user = u;
ctrl->rear->group = g;
if(ctrl->rear->sense->prev->gen != -1)
ctrl->rear->sense->prev->gen = 0;
/*Asignación del proceso a la lista de
procesos del grupo correspondiente*/
/*En caso de que el grupo no tenga procesos
asignados */
printf("Ligando proceso con su grupo...\n");
if(g->pcbG->front == NULL)
{
g->pcbG->front = ctrl->rear;
g->pcbG->rear = g->pcbG->front;
g->pcbG->rear->groupSense->prev = g->pcbG->front;
g->pcbG->front->groupSense->prev = g->pcbG->rear;
g->pcbG->front->groupSense->next = g->pcbG->rear;
g->pcbG->rear->groupSense->next = g->pcbG->front;
}
/*Caso en el que ya existan procesos con el
grupo elegido*/
else
{
g->pcbG->rear->groupSense->next = ctrl->rear;
g->pcbG->rear->groupSense->next->groupSense->prev = ctrl->rear;
g->pcbG->rear = g->pcbG->rear->groupSense->next;
g->pcbG->rear->groupSense->next = g->pcbG->front;
g->pcbG->front->groupSense->prev = g->pcbG->rear;
}
/*Asignación del proceso a la lista de
procesos del usuario correspondiente*/
/*En caso de que el usuario no tenga procesos
asignados */
printf("Ligando proceso con su usuario...\n");
if(u->pcbU->front == NULL)
{
u->pcbU->front = ctrl->rear;
u->pcbU->rear = u->pcbU->front;
u->pcbU->rear->userSense->prev = u->pcbU->front;
u->pcbU->front->userSense->prev = u->pcbU->rear;
u->pcbU->front->userSense->next = u->pcbU->rear;
u->pcbU->rear->userSense->next = u->pcbU->front;
}
/*Caso en el que ya existan procesos con el
usuario elegido*/
else
{
u->pcbU->rear->userSense->next = ctrl->rear;
u->pcbU->rear->userSense->next->userSense->prev = ctrl->rear;
u->pcbU->rear = u->pcbU->rear->userSense->next;
u->pcbU->rear->userSense->next = u->pcbU->front;
u->pcbU->front->userSense->prev = u->pcbU->rear;
}
printf("Encolando elemento a la lista de ejecucion...\n");
if(states->readys->front == NULL)
{
states->readys->front = ctrl->rear;
states->readys->rear = states->readys->front;
states->readys->rear->stateSense->next = states->readys->front;
states->readys->rear->stateSense->prev = states->readys->front;
states->readys->front->sense->prev = states->readys->rear;
states->readys->front->stateSense->next = states->readys->rear;
}
else
{
states->readys->rear->stateSense->next = ctrl->rear;
states->readys->front->stateSense->prev = ctrl->rear;
states->readys->rear->stateSense->next->stateSense->prev = ctrl->rear;
states->readys->rear = states->readys->rear->stateSense->next;
states->readys->rear->stateSense->next = states->readys->front;
}
printf("Proceso creado.\n");
}
else
printf("%s\n",MEM_FAIL);
}
}
}
}
}
}
}
/*Imprime los campos que tiene un proceso*/
void print_pcbInfo(pcb *aux)
{
printf("|%6i|", aux->pid);
printf("%4i|", aux->cp);
printf("%4i", aux->group->gid);
printf("%16s|",aux->group->n);
printf("%4i", aux->user->uid);
printf("%16s|",aux->user->n);
printf("%5i|", aux->tim[0]);
printf("%8i|", aux->tim[1]);
printf("%9i|", aux->tim[2]);
switch(aux->state)
{
case 1:
printf("%10s|", EJEC);
break;
case 2:
printf("%10s|", LIS);
break;
case 3:
printf("%10s|", ESP);
break;
case 4:
printf("%10s|", DOR);
break;
}
printf("\n");
aux = NULL;
}
/*Ejecuta el siguiente proceso en la cola de listos con el
algoritmo de despacho Round Robin*/
void rr(pcbStates *states, pcbCtrl *ctrl, int quantum, int *totalTime)
{
pcb *temp,*f = states->readys->front;
if(states->readys->front != NULL)
{
if(states->readys->front->first_exe == 0)
{
if(states->readys->front == states->readys->rear)
{
printf("Proceso comenzando ejecución en tiempo: %i\n\n",*totalTime);
states->readys->front->state = ID_EJEC;
states->readys->front->first_exe = 1;
if(states->readys->front->tim[1] <= quantum)
{
*totalTime += execute(quantum,states->readys->front);
printf("\nProceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
temp = find_pcb(states->readys->front->pid,ctrl->front);
temp->state = ID_LIS;
changer(states->sleeping,temp,states);
temp->state = ID_DOR;
}
else
{
*totalTime += execute(quantum,states->readys->front);
printf("\nProceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
temp = states->readys->front;
temp->state = ID_LIS;
changer(states->waiting, states->readys->front, states);
temp->state = ID_ESP;
}
}
else
{
printf("Proceso comenzando ejecución en tiempo: %i\n\n",*totalTime);
states->readys->front->state = ID_EJEC;
if(states->readys->front->tim[1] <= quantum)
{
*totalTime += execute(quantum,states->readys->front);
printf("\nProceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
temp = find_pcb(states->readys->front->pid,ctrl->front);
temp->state = ID_LIS;
changer(states->sleeping,temp,states);
temp->state = ID_DOR;
}
else
{
*totalTime += execute(quantum,states->readys->front);
printf("\nProceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
temp = states->readys->front;
temp->state = ID_LIS;
changer(states->waiting, states->readys->front, states);
temp->state = ID_ESP;
}
}
temp->first_exe = 1;
}
else
{
if(states->readys->front == states->readys->rear)
{
printf("Proceso comenzando ejecución en tiempo: %i\n\n",*totalTime);
states->readys->front->state = ID_EJEC;
if(states->readys->front->tim[1] <= quantum)
{
*totalTime += execute(states->readys->front->tim[1],states->readys->front);
printf("Proceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
temp = states->readys->front;
temp->state = ID_LIS;
changer(states->sleeping,temp,states);
temp->state = ID_DOR;
}
else
{
*totalTime += execute(quantum,states->readys->front);
printf("Proceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
states->readys->front->state = ID_LIS;
}
}
else
{
printf("Proceso comenzando ejecución en tiempo: %i\n\n",*totalTime);
states->readys->front->state = ID_EJEC;
if(states->readys->front->tim[1] <= quantum)
{
*totalTime += execute(states->readys->front->tim[1],states->readys->front);
printf("Proceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
temp = states->readys->front;
temp->state = ID_LIS;
changer(states->sleeping,temp,states);
temp->state = ID_DOR;
}
else
{
*totalTime += execute(quantum,states->readys->front);
printf("Proceso terminando ejecucion en tiempo: %i\n\n",*totalTime);
states->readys->front->state = ID_LIS;
states->readys->front->stateSense->next->stateSense->prev = states->readys->rear;
states->readys->rear = states->readys->front;
states->readys->front = states->readys->front->stateSense->next;
}
}
}
}
else
printf("%s\n",EMPTY_FAIL);
}
/*Hace que se ejecute un proceso por un tiempo maximo*/
int execute(int t,pcb *exec)
{
int i;
for(i = 0; i < t; i++)
{
if(exec->tim[1] > 0)
{
exec->tim[1]--;
exec->tim[2]++;
}
else
break;
print_options(2);
print_pcbInfo(exec);
printf("\n");
}
return i;
}
/*Muestra los procesos existentes de acuerdo a su momento
de llegada*/
void show_pcb(pcbCtrl *ctrl)
{
if(ctrl->front != NULL)
{
pcb *f = ctrl->front;
printf("\t\tTABLA DE PROCESOS\n\n");
print_options(2);
do
{
print_pcbInfo(f);
}while(next_pcb(&f, ctrl->front) != FAIL);
printf("\n");
}
}
/*Muestra los procesos en funcion a lo que el usuario quiera
ver, puede ser por estado, grupo, usuario, o momento de
llegada y además da la opcion de mostrarlo desde el inicio
de la lista seleccionada o desde su fin*/
void show_everything(pcbCtrl *ctrl, pcbStates *states, groupsCtrl *ctrlG, usersCtrl *ctrlU)
{
int ch,what, how;
users *user;
groups *group;
int state, gid, uid;
pcb *f, *r;
do
{
printf("%s que desea ver\n",SELEC);
print_options(3);
printf("(4) Cancelar.\n");
printf("\n>");
scanf("%i",&ch);
getchar();
switch(ch)
{
case 1:
if(ctrlG->front != NULL)
show_groups(ctrlG);
else
printf("No hay grupos\n");
break;
case 2:
if(ctrlU->front != NULL)
show_users(ctrlU);
else
printf("No hay usuarios\n");
break;
case 3:
if(ctrl->front != NULL)
{
do
{
print_options(1);
printf("(5) Cancelar.\n");
printf("\n>");
scanf("%i",&what);
getchar();
if(what != 5)
{
do
{
printf("\n%s desde donde comenzar a ver los procesos.\n",SELEC);
printf("(1) Desde el inicio.\n(2) Desde el fin.\n(3) Cancelar.\n");
printf("\n>");
scanf("%i",&how);
getchar();
if(how == 1)
{
switch(what)
{
/*Muestra los procesos por estado a partir del inicio*/
case 1:
state = print_states(0);
switch(state)
{
case 1:
printf("%s en ejecucion·\n",EMPTY_FAIL);
break;
case 2:
if(states->readys->front != NULL)
{
f = states->readys->front;
printf("\t\t\t<< PROCESOS LISTOS PARA EJECUTARSE >>\n");
print_options(2);
do
{
print_pcbInfo(f);
}while(next_pcb_states(&f, states->readys->front) != FAIL);
}
else
printf("%s listos para ejecutarse·\n",EMPTY_FAIL);
break;
case 3:
if(states->waiting->front != NULL)
{
f = states->waiting->front;
printf("\t\t\t<< PROCESOS ESPERANDO EVENTO PARA EJECUTARSE >>\n");
print_options(2);
do
{
print_pcbInfo(f);
}while(next_pcb_states(&f, states->waiting->front) != FAIL);
}
else
printf("%s en espera de eventos·\n",EMPTY_FAIL);
break;
case 4:
if(states->sleeping->front != NULL)
{
f = states->sleeping->front;
printf("\t\t\t\t<< PROCESOS DORMIDOS >>\n");
print_options(2);
do
{
print_pcbInfo(f);
}while(next_pcb_states(&f, states->sleeping->front) != FAIL);
}
else
printf("%s dormidos·\n",EMPTY_FAIL);
break;
}
break;
/*Muestra los procesos por grupo a partir del inicio*/
case 2:
printf("%s el grupo del que desea ver sus procesos.\n",SELEC);
show_groups(ctrlG);
printf("\n>");
scanf("%i",&gid);
getchar();
group = find_group(gid,ctrlG->front);
if(group->pcbG->front != NULL)
{
printf("\t\t\t\t<< PROCESOS DEL GRUPO %s >>\n",group->n);
print_options(2);
f = group->pcbG->front;
do
{
print_pcbInfo(f);
}while(next_pcbG(&f,group->pcbG->front) != FAIL);
}
else
printf("%s pertenecientes a grupo seleccionado.\n",EMPTY_FAIL);
break;
/*Muestra los procesos por usuario a partir del inicio*/
case 3:
printf("%s el usuario de los procesos a mostrar.\n",SELEC);
show_users(ctrlU);
printf("\n>");
scanf("%i",&uid);
getchar();
user = find_user(uid,ctrlU->front);
if(user->pcbU->front != NULL)
{
printf("\t\t\t\t<< PROCESOS DEL USUARIO %s >>\n",user->n);
print_options(2);
f = user->pcbU->front;
do
{
print_pcbInfo(f);
}while(next_pcbU(&f,user->pcbU->front) != FAIL);
}
else printf("%s pertenecientes al usuario seleccionado·\n",EMPTY_FAIL);
break;
/*Muestra los procesos por momento de llegada a partir del inicio*/
case 4:
f = ctrl->front;
printf("\t\t\t\t<< TABLA DE PROCESOS >>\n\n");
print_options(2);
do
{
print_pcbInfo(f);
}while(next_pcb(&f, ctrl->front) != FAIL);
break;
}
}
else if(how == 2)
{
switch(what)
{
/*Muestra los procesos por estado a partir del fin*/
case 1:
state = print_states(0);
switch(state)
{
case 1:
printf("%s en ejecucion.\n",EMPTY_FAIL);
break;
case 2:
if(states->readys->front != NULL)
{
r = states->readys->rear;
printf("\t\t\t<< PROCESOS LISTOS PARA EJECUTARSE >>\n");
print_options(2);
do
{
print_pcbInfo(r);
}while(prev_pcb_states(&r, states->readys->rear) != FAIL);
}
else printf("%s listos para ejecutarse.\n",EMPTY_FAIL);
break;
case 3:
if(states->waiting->front != NULL)
{
r = states->waiting->rear;
printf("\t\t\t<< PROCESOS ESPERANDO EVENTO PARA EJECUTARSE >>\n");
print_options(2);
do
{
print_pcbInfo(r);
}while(prev_pcb_states(&r, states->waiting->rear) != FAIL);
}
else printf("%s esperando eventos.",EMPTY_FAIL);
break;
case 4:
if(states->sleeping->front)
{
r = states->sleeping->rear;
printf("\t\t<< PROCESOS DORMIDOS >>\n");
print_options(2);
do
{
print_pcbInfo(r);
}while(prev_pcb_states(&r, states->sleeping->rear) != FAIL);
}
else printf("%s dormidos.\n",EMPTY_FAIL);
break;
}
break;
/*Muestra los procesos por grupo a partir del fin*/
case 2:
printf("%s el grupo del que desea ver sus procesos.\n",SELEC);
show_groups(ctrlG);
printf("\n>");
scanf("%i",&gid);
getchar();
group = find_group(gid,ctrlG->front);
if(group->pcbG->front != NULL)
{
printf("\t\t<< PROCESOS DEL GRUPO %s >>\n",group->n);
print_options(2);
r = group->pcbG->rear;
do
{
print_pcbInfo(r);
}while(prev_pcbG(&r,group->pcbG->rear) != FAIL);
}
else printf("%s pertenecientes al grupo seleccionado.\n",EMPTY_FAIL);
break;
/*Muestra los procesos por usuario a partir del fin*/
case 3:
printf("%s el usuario de los procesos a mostrar.\n",SELEC);
show_users(ctrlU);
printf("\n>");
scanf("%i",&uid);
getchar();
user = find_user(uid,ctrlU->front);
if(user->pcbU->front != NULL)
{
printf("\t\t<< PROCESOS DEL USUARIO %s >>\n",user->n);
print_options(2);
r = user->pcbU->rear;
do
{
print_pcbInfo(r);
}while(prev_pcbU(&r,user->pcbU->rear) != FAIL);
}
else printf("%s pertenecientes al usuario seleccionado\n",EMPTY_FAIL);
break;
/*Muestra los procesos por momento de llegada a partir del fin*/
case 4:
r = ctrl->rear;
printf("\t\t\t\t<< TABLA DE PROCESOS >>\n\n");
print_options(2);
do
{
print_pcbInfo(r);
}while(prev_pcb(&r, ctrl->rear) != FAIL);
break;
}
}
if(how == 3)
break;
}while(how != 3);
}
}while(what != 5);
}
else
printf("%s.\n",EMPTY_FAIL);
break;
case 4:
break;
default:
printf("%s\n",DEFAULT_FAIL);
}
}while(ch != 4);
}
/*1_Eliminacion de un proceso*/
int del_pcss(pcbCtrl *ctrl, pcbStates *states)
{
pcb *elm;
if( states->sleeping->front != NULL )
{
int eleccion; //Eleccion de grupo
elm = NULL;
printf("\n<< Eliminación de proceso >>\n");
do
{
printf("Escoja el proceso a eliminar:\n\n");
print_options(2);
if( show_pcb_sleeping(states) )
{
do
{
printf("\n>");
scanf("%i", &eleccion);
getchar();
}while(val_npos(eleccion, 0) == FAIL);
elm = find_pcb(eleccion, states->sleeping->front);
}
}while( val_mem( (void *) elm) );
del_pcss_reaper(ctrl, states, elm);
}
else
printf("%s para eliminar. Solo los procesos dormidos pueden ser eliminados.\n",EMPTY_FAIL);
}
/*0_Eliminacion de grupo junto con sus procesos*/
/*Elimina los procesos de la tabla de control y tambien los borra de la lista de dormidos*/
void del_pcss_reaper(pcbCtrl *ctrl, pcbStates *states, pcb *elm)
{
pcb *aux;
int flag;
aux = elm;
if(aux->gen == FRONT)
{
if(ctrl->front->sense->next == ctrl->front)
{
//Caso en el que solo exista un proceso creado
ctrl->rear = ctrl->front = NULL;
}
else
{
//Caso en el que es el frente pero no es el unico elemento
ctrl->front = ctrl->front->sense->next;
ctrl->front->sense->prev = ctrl->rear;
ctrl->rear->sense->next = ctrl->front;
}
}
else
if(aux->gen == REAR)
{
//Caso en el que es el frente pero no es el unico elemento
ctrl->rear = ctrl->rear->sense->prev;
ctrl->front->sense->prev = ctrl->rear;
ctrl->rear->sense->next = ctrl->front;
}
else //Caso en el que es cualquier otro elemento de la pcb
{
elm->sense->next->sense->prev = elm->sense->next;
elm->sense->prev->sense->next = elm->sense->prev;
}
flag = 0;
//1_Eliminacion del proceso en la lisa de dormidos
if(states->sleeping->front->stateSense->next == states->sleeping->front)
{
states->sleeping->rear = states->sleeping->front = NULL;
flag++;
}
else
if(elm == states->sleeping->front)
{
states->sleeping->front->stateSense->next->stateSense->prev = states->sleeping->rear;
states->sleeping->front = states->sleeping->front->stateSense->next;
states->sleeping->rear->stateSense->next = states->sleeping->front;
flag++;
}
else
if(elm == states->sleeping->rear)
{
states->sleeping->rear->stateSense->prev->stateSense->next = states->sleeping->front;
states->sleeping->rear = states->sleeping->rear->stateSense->prev;
states->sleeping->front->stateSense->prev = states->sleeping->rear;
flag++;
}
else
{
elm->stateSense->prev->stateSense->next = elm->stateSense->next;
elm->stateSense->next->stateSense->prev = elm->stateSense->prev;
}
//0_Eliminacion del proceso en la lista de dormidos
//1_Eliminacion del proceso en la lista de proceso del grupo
if(elm->group->pcbG->front == elm->group->pcbG->rear)
elm->group->pcbG->front = elm->group->pcbG->rear = NULL;
else
if(elm == elm->group->pcbG->front)
{
elm->group->pcbG->front = elm->groupSense->next;
elm->group->pcbG->rear->groupSense->next = elm->group->pcbG->front;
elm->group->pcbG->front->groupSense->prev = elm->group->pcbG->rear;
}
else