简体   繁体   中英

Measuring a process context switch

I am creating a C program to measure a process switch for a project, and I am having a couple difficulties. The method I am using is to create 2 pipes, parentpipe and childpipe. The parent writes one byte in to its pipe then reads the child pipe, theoretically forcing control to the child pipe. The child e reads the parent pipe and writes a byte to the child pipe.

Here are my issues:

  1. The processes aren't actually forced to switch. If I use sleep instead of the above method then they switch, but I'm trying not to use sleep. How do i force them to switch?

  2. I am using CLOCK_MONOTONIC to measure and can't figure out where to put the start and stop for it. I keep getting junk values no matter where I put them (assuming I put one in each process:start in one and stop in the other). Where do i put the clocks?

Thank you for your help.

  1. Be sure to select unbuffered i/o. Otherwise read and write wait for more characters before returning, even when only one byte is requested.

  2. Record CLOCK_MONOTONIC at the beginning of the program and subtract it from all subsequent timestamps. Typically CLOCK_MONOTONIC is implemented as the time since the system booted. Suggesting where to put the measurement would be easier if you showed your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM