How to automatically close the execution of the `qemu` after end of process?
Asked Answered
W

2

7

I want that the qemu window after opening and showing the output automatically closes after running pintOS

Like when i run the command pintos -- run alarm-multiple in tcsh shell, qemu displays that process begins ,then some alarm-notifications and then the process ends, but after that the qemu window won't close

I want to exit the window after successful completion of my system call.

Westsouthwest answered 13/2, 2017 at 15:55 Comment(2)
This indicates your pintOS doesn't exit properly. Make sure it exits properly i.e. return to it's parent.Blank
I guess, you haven't read my problem properly. I want the qemu window to close automatically, there is no problem in pintOS.Westsouthwest
P
6

UPDATED:


The new solution

Here is another better solution that will work for both pintos run ... and make grade

add this line to devices/shutdown.c :: shutdown_power_off(void) before the loop.

outw( 0x604, 0x0 | 0x2000 ); 

The old Solution

For the newer versions of qemu you need to run it with the option

-device isa-debug-exit

Which exits on any write to an IO port, by default it's 0x501

i.e in your pintos project under the src/utils directory you will need to add one line to the pintos file in the run_qemu subroutine

sub run_qemu {
    print "warning: qemu doesn't support --terminal\n"
       if $vga eq 'terminal';
    print "warning: qemu doesn't support jitter\n"
       if defined $jitter;
    my (@cmd) = ('qemu-system-i386');

    push (@cmd, '-device', 'isa-debug-exit'); # <====== add this line
    ..
    ..
    push (@cmd, '-monitor', 'null') if $vga eq 'none' && $debug eq 'none';
    run_command (@cmd);
}

and in shutdown.c file under the devices directory add this line in the shutdown_power_off function after the for loop

for (p = s; *p != '\0'; p++)
    outb (0x8900, *p);

outb (0x501, 0x31); // <====== add this line

Qemu's exit code is double the value plus one, so there is no way to exit cleanly. Use 0x31 which should result in a qemu exit code of 0x63

finally run pintos with -q option

pintos -q run alarm-multiple
  • Note: this solution will not work for make grade see the comment below by @pranav3688 for a solution.
Parapet answered 17/11, 2017 at 4:45 Comment(2)
this works in general case, but fails when make grade is executed with qemu because it needs a clean exit (return code = 0 and not 0x63).... to remedy this, change line 896 of sub xsystem of pintos script to return 0 from return $? (which return 0x63 )Corcyra
Yes, you are right. Actually, I also found another solution other than the one I wrote, you can just add this line => outw( 0x604, 0x0 | 0x2000 ); in /shutdown.c : shutdown_power_off(void) before the loop. Tell me if this works too, I will update the post for both solutions.Parapet
C
0

[I recognize the question refers specifically to pintos, but I found myself learning from the answers here, enough to do this under Linux. I thought I would leave this here in case others came to this page for similar reasons...]

I found myself doing this for testing purposes. Here is the code I used (run as root from within the QEMU session):

#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>
#include <unistd.h>

#define SHUTDOWN_PORT 0x604
#define EXIT_PORT     0x501

static void clean_exit(void) {
    ioperm(SHUTDOWN_PORT, 16, 1);
    outw(0x2000, SHUTDOWN_PORT);
}

int main(int argc, char **argv) {
    int status;
    if (argc != 2) {
        clean_exit();
    }
    status = atoi(argv[1]);
    printf("exiting with status %d (in three seconds)\n", status);
    sleep(3);
    if (!status) {
        clean_exit();
    }
    ioperm(EXIT_PORT, 8, 1);
    /*
     * status returned is 1+(2*orig_status)
     */
    outb(status-1, EXIT_PORT);
    printf("didn't exit.. did you include '-device isa-debug-exit'"
        " in qemu command?\n");
    exit(1);
}

My QEMU environment image is pretty sparse, so I compile it statically as follows:

$ gcc -O2 exit.c -o exit --static

Usage:

   Just exit with status 0    # ./exit
   Same as above              # ./exit 0
   Exit with status 1         # ./exit 1
   Exit with status 1+2*(n-1) # ./exit n

For my purposes I only really use exit, exit 0 and exit 1.

Combative answered 13/3, 2021 at 23:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.